Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP无法加载图像并显示它_Php_Image_Header_Content Type_Loadimage - Fatal编程技术网

PHP无法加载图像并显示它

PHP无法加载图像并显示它,php,image,header,content-type,loadimage,Php,Image,Header,Content Type,Loadimage,我正试图制作一个php脚本来加载图像,并根据$\u GET参数显示它 我想稍后使用它将图像加载到我的移动应用程序(Android)中 问题是我无法使图像显示。我使用以下代码: header("Content-Type: image/jpeg"); readfile($path); 但当我在firefox中打开页面时,我得到了一个错误: Image cannot be displayed because it contains errors. 此外,我还尝试了不同的方法,可以在html代码中显

我正试图制作一个php脚本来加载图像,并根据$\u GET参数显示它

我想稍后使用它将图像加载到我的移动应用程序(Android)中

问题是我无法使图像显示。我使用以下代码:

header("Content-Type: image/jpeg");
readfile($path);
但当我在firefox中打开页面时,我得到了一个错误:

Image cannot be displayed because it contains errors.
此外,我还尝试了不同的方法,可以在html代码中显示图像(我不想这样做——这需要在java android中删除标题——但它证明了路径是正确的)

echo'
我做错了什么?有什么想法吗?
提前感谢。

之前有输出吗?请确保在发送标题之前没有输出任何字符!另请参见:我只看到错误,这意味着标题被正确包含,我的浏览器试图以图像形式打开页面。@Alek您必须检查输出。我连接到mysql数据库的文件中有一个空格,用于验证参数。删除了它,它就可以工作了。之前有输出吗?确保在发送标题之前没有输出任何字符!另请参见:我只看到错误,这意味着标题被正确包含,我的浏览器试图以图像形式打开页面。@Alek您必须检查输出。我连接到mysql数据库的文件中有一个空格,用于验证参数。删除它,它的工作。
echo '<img src="data:image/jpeg;base64,'.base64_encode(file_get_contents($path) ).'"/>