[php调用php文件作为公共目录之外的图像

问题描述 投票:0回答:1

在公共目录之外的目录privateimgdir中,我有文件create_img.php可以动态创建png图像。我需要从公共目录之外提供该img,以避免其他站点直接访问输出图像。

为此,我正在尝试使用php代理脚本。在public_scripts目录中,我具有文件take_img.php,其代码如下:

<?php

$file_to_get = basename(urldecode($_GET['file']));

$private_image_dir = "../../privateimgdir/";

$contents = file_get_contents($private_image_dir . $file_to_get);

header('Content-type: image/png');

echo $contents;

?>

现在,我尝试使用以下代码来调用take_img.php脚本,并将create_img.php文件名作为参数传递:

echo "<a href='public_scripts/take_img.php?file=create_img.php'></a>";

但是我没有输出。我在哪里错了?

php directory get private
1个回答
0
投票

几件事:

© www.soinside.com 2019 - 2024. All rights reserved.