hkv*_*ega 10 php image-processing
我想通过使用img标签打印图像,其中src是一个php文件,该脚本还将在服务器scirpt处理一些操作.有人有示例代码吗?
这是我的测试代码,但没有效果
img.html
<img src="visitImg.php" />
Run Code Online (Sandbox Code Playgroud)
visitImg.php
<?
header('Content-Type: image/jpeg');
echo "<img src=\"btn_search_eng.jpg\" />";
?>
Run Code Online (Sandbox Code Playgroud)
Mar*_*itz 12
使用readfile:
<?php
header('Content-Type: image/jpeg');
readfile('btn_search_eng.jpg');
?>
Run Code Online (Sandbox Code Playgroud)
直接来自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;
?>
Run Code Online (Sandbox Code Playgroud)
作为解释,您需要将图像数据作为脚本的输出传递,而不是 html数据.您可以使用其他功能,如fopen,readfile,等等等等
UPDATE
你可以做什么而不用include如下面评论中所述:
试试这个:
<?
$img="example.gif";
header ('content-type: image/gif');
readfile($img);
?>
Run Code Online (Sandbox Code Playgroud)
上面的代码来自这个网站
原始答案
不要试试这个:
<?
header('Content-Type: image/jpeg');
include 'btn_search_eng.jpg'; // SECURITY issue for uploaded files!
?>
Run Code Online (Sandbox Code Playgroud)