Broken image with readfile and file_get_contents

杀马特。学长 韩版系。学妹 提交于 2019-11-29 10:52:26

You certainly have some whitespace in your PHP script, or a UTF-8 BOM invisibly before your <?php opening marker. Use a hexeditor to find out.

To debug it further, open the image URL http://localhost/login.php?image=ind_legend.jpg directly in your browser, save the file. And then compare it to the original JPEG.

use the ob_clean() function of php before the readfile()

As previously mentioned, you probably have some whitespace. I'd try replacing the entire file with the code below. Removing the closing php statement eliminates any chance that there is extra whitespace:

<?php
$file = "http://localhost/sales/test.jpg";
header('Content-type: image/jpeg');
readfile($file);

first of all point your browser to http://youraddress/login.php?image=ind_legend.jpg and check the result.

Maybe the file /sales/test.jpg is corrupted or you don't have enabled the http:// wrapper for readline

At last save the corrupted image via the save image as... context menu option of your browser of choice and try to open it with a text editor. I will not surprised if you will find an error message (if you have them enabled).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!