워드프레스 path 경로 관해 질문드립니다.

gd library를 사용하여 디비에서 끌어온 텍스트들을 이미지화 하려 합니다.

 

도메인명/?page_id=565

위 주소로 숏코드를 넣어둔 상태입니다.

숏코드는 functions.php에 있으며, 아래와 같이 테스트 코드를 작성해두었습니다.

add_shortcode('image_test','image_test');

function image_test(){
	ob_start();
	include "test.php";
	return ob_get_clean();
}

아래는 test.php이며 차일드 테마 폴더 내 functions.php와 함께 있습니다. 

<?php

header("Content-type: image/png");
  $string = "ekjaetkt";
  $im     = imagecreatefrompng("button.png");
  $orange = imagecolorallocate($im, 60, 87, 156);
  $px     = (imagesx($im) - 7.5 * strlen($string)) / 2;
  imagestring($im, 4, $px, 9, $string, $orange);
  imagepng($im);
  imagedestroy($im);

?>

도메인명/?page_id=565 이 주소로 접속시에는 안되고

도메인명/wp-content/themes/astra-child/test.php 이 주소로 직접 파일을 열어볼경우는 됩니다.

왜 이런 현상이 생기는걸까요 ...?ㅠ

 

현재 워드프레스 고유주소는 일반으로 되어있습니다. test.php와 연결은 되어있는듯 합니다. 간단한 테스트로 echo "테스트"; 의 경우는 잘 나옵니다.

워드프레스 에러 기술지원 서비스 전문가에게 맡기세요
워드프레스 에러 기술지원 서비스 전문가에게 맡기세요
  • 안녕하세요~^^

    차일드테마의 한 폴더에 functions.php 파일과 test.php 파일이 같이 있으신건가요?

    차일드테마에서 파일을 불러올 때는

    아래 코드와 같이

    <?php include(get_stylesheet_directory() . '/test.php'); ?>

    get_stylesheet_directory() 함수를 사용하실 수 있습니다.

    위 코드를 참고하셔서 적용해보시겠어요?

    고맙습니다.

  • test.php를 템플릿으로 만들어

    <?php
    
    /*
    Template Name: 이미지 저장 템플릿
    */
    
    
    get_header();
    
    header("Content-type: image/png");
      $string = "ekjaetkt";
      $im     = imagecreatefrompng("button.png");
      $orange = imagecolorallocate($im, 60, 87, 156);
      $px     = (imagesx($im) - 7.5 * strlen($string)) / 2;
      imagestring($im, 4, $px, 9, $string, $orange);
      imagepng($im);
      imagedestroy($im);
    
    get_footer();
    
    ?>
    

    도메인명/?page_id=454 으로 템플릿 지정한 후 접속하면 나오지가 않습니다...

     

    콘솔창에서 header 부분

    1. Cache-Control:

      no-cache, must-revalidate, max-age=0

    2. Content-Type:

      image/png

    3. Date:

      Fri, 13 Aug 2021 21:01:03 GMT

    4. Expires:

      Wed, 11 Jan 1984 05:00:00 GMT

    5. Link:

      <http://co2diet.net/index.php?rest_route=/>; rel="https://api.w.org/"

    6. Link:

      <http://co2diet.net/index.php?rest_route=/wp/v2/pages/565>; rel="alternate"; type="application/json"

    7. Link:

      <http://co2diet.net/?p=565>; rel=shortlink

    8. Pragma:

      no-cache

    9. Server:

      nginx

    10. X-Powered-By:

      PHP/7.3.1p1

    <?php
    
    
    header("Content-type: image/png");
      $string = "ekjaetkt";
      $im     = imagecreatefrompng("button.png");
      $orange = imagecolorallocate($im, 60, 87, 156);
      $px     = (imagesx($im) - 7.5 * strlen($string)) / 2;
      imagestring($im, 4, $px, 9, $string, $orange);
      imagepng($im);
      imagedestroy($im);
    
    
    ?>
    

    이렇게 위 코드만 넣은 상태로 

    도메인명/wp-content/themes/astra-child/test.php

    이런식으로만 접속해야 정상적으로 이미지로 나오는데요.. 무슨 문제일까요

     

    콘솔창에서 header 부분

    1. Connection:

      keep-alive

    2. Content-Length:

      361

    3. Content-Type:

      image/png

    4. Date:

      Fri, 13 Aug 2021 20:52:18 GMT

    5. Server:

      nginx

    6. X-Powered-By:

      PHP/7.3.1p1

     

    제가 주소에 대한 개념이 없는건지... ?page_id=xxx 이런식으로 접근했을때의 보안적인 문제가있는건지

     

  • 혹시 올려주신 코드에서

    아래 코드 부분을

    imagecreatefrompng("button.png");

    아래처럼 변경해서 적용해보시겠어요?

    imagecreatefrompng(get_template_directory() . "/button.png");

     

    기능을 추가하실 때는 디버그 모드를 활성화 하시면

    원인을 파악하는데 도움이 됩니다.

    워드프레스 에러 확인하기 - 디버그 모드 활성화 방법

    고맙습니다.

워드프레스 에러 기술지원 서비스 전문가에게 맡기세요