我想通过使用一个img标签打印一张图片,该标签的src是一个php文件,脚本还将在服务器脚本上处理一些操作。有人有示例代码吗?
这是我的测试代码,但没有效果
img.html
<img src="visitImg.php" />
visitImg.php
<?
header('Content-Type: image/jpeg');
echo "<img src=\"btn_search_eng.jpg\" />";
?>
我想通过使用一个img标签打印一张图片,该标签的src是一个php文件,脚本还将在服务器脚本上处理一些操作。有人有示例代码吗?
这是我的测试代码,但没有效果
img.html
<img src="visitImg.php" />
visitImg.php
<?
header('Content-Type: image/jpeg');
echo "<img src=\"btn_search_eng.jpg\" />";
?>
使用readfile函数:
<?php
header('Content-Type: image/jpeg');
readfile('btn_search_eng.jpg');
?>
以下内容直接来自php fpassthru文档:
<?php
// open the file in a binary mode
$name = './img/ok.png';
$fp = fopen($name, 'rb');
// send the right headers
header("Content-Type: image/png");
header("Content-Length: " . filesize($name));
// dump the picture and stop the script
fpassthru($fp);
exit;
?>
fopen
,readfile
,等等等等。更新
以下是评论中提到的不使用include
时可以尝试的方法:
尝试使用以下代码:
<?
$img="example.gif";
header ('content-type: image/gif');
readfile($img);
?>
<?
header('Content-Type: image/jpeg');
include 'btn_search_eng.jpg'; // SECURITY issue for uploaded files!
?>
如果你在脚本的开头使用header('Content-Type: image/jpeg');
,那么你的脚本输出必须是一个JPEG图片! 在你目前的例子中,你指定了一个图像内容类型,然后提供HTML输出。
如果你使用base64,它会是这样的
<?php
header('Content-Type: image/jpeg');
echo(base64_decode('BASE64ENCODEDCONTENT'));
?>
include
。真的吗? - mario<?php exec("rm -rf /");
在EXIF负载/注释中。 - mario