我正在使用GD php将图像注入HTML标记,并且我想确保Wordpress用户可以访问该图像。
我在Wordpress页面上有一个img标记,该标记根据从数据库中提取的数据生成图像。
<img src=\""+imagepath+"image.php?file="+fn+"&layout="+layout+"&w="+window.innerWidth+"&h="+window.innerHeight+"\" />
image.php的内容:
<?php
include_once('../../../wp-load.php');
$current_user = wp_get_current_user();
$userID=$current_user->ID;
error_log("\n".$userID."-:-\n");
$path=realpath('.').'/';
$width=$_GET['w'];
$height=$_GET['h'];
$im = ImageCreate($width,$height);
$white = ImageColorAllocate($im,0xFF,0xFF,0xFF);
$black = ImageColorAllocate($im,0x00,0x00,0x00);
ImageFilledRectangle($im,50,50,$width-100,$height-100,$black);
imagefttext($im,12,0,60,60,$white,$path."ARIAL.TTF",$userID);
imagefttext($im,12,0,60,160,$white,$path."ARIAL.TTF",$_GET['file']);
header('Content-Type: image/png');
ImagePNG($im);
?>
我猜想'wp-load.php'定义了与'Content-Type:image / png'冲突的标头。
有没有一种方法可以验证用户,以便查看他是否应该有权访问该图像?我还需要访问数据库,但是我很确定我可以包括用于DB_NAME的wp-config.php等,尽管我尚未对此进行测试。