将image的路径作为get参数传递给showImage.php脚本。
<?php $pathToPicture = "server/www/images/imagexyz1823014719102714123.png"; ?>
<img src="/resources/php/showImage.php?pathToPicture=<?php echo $pathToPicture;?>" >
在这里你可以得到传递的变量从$_GET
数组:
<?php
header('Content-Type: image/jpeg');
readfile($_GET['pathToPicture']);
?>
我最好建议使用BASE64_ENCODE和BASE64_DECODE为pathToPicture
用于这一目的。也不要公开像这样公开你的图像位置的整个路径。有一个看看下面改进的代码
<?php $pathToPicture = "imagexyz1823014719102714123.png"; ?>
<img src="/resources/php/showImage.php?pathToPicture=<?php echo base64_encode($pathToPicture);?>" >
<?php
$location = "server/www/images/";
$image = !empty($_GET['pathToPicture']) ? base64_decode($_GET['pathToPicture']) : 'default.jpg';
// In case the image requested doesn't exist.
if (!file_exists($location.$image)) {
$image = 'default.jpg';
}
header('Content-Type: '.exif_imagetype($location.$image));
readfile($location.$image);
?>
的可能的复制[如何通过使用GET而不型PHP变量?](http://stackoverflow.com/questions/6074699/how-to-pass-variables- in-php-using-get-without-type) – Chuck