Home  >  Article  >  Backend Development  >  How to solve the problem that php images cannot be displayed due to errors

How to solve the problem that php images cannot be displayed due to errors

藏色散人
藏色散人Original
2020-08-13 10:58:362748browse

Solution to the problem that php cannot be displayed due to errors: 1. Turn off the notice error prompt of wamp through the "error_reporting(E_ALL & ~E_NOTICE);" method; 2. Define "$file" before the PHP code file =”;”.

How to solve the problem that php images cannot be displayed due to errors

Recommended: "PHP Video Tutorial"

php image due to errors And it cannot be displayed

(The picture above is displayed by Firefox browser, and Google browser displays a cross)

<?php
header("Content-type:image/jpeg");
 
$resource = fopen(&#39;001.png&#39;,&#39;r&#39;);
while($ff = fread($resource, 1024)){
    $file .= $ff;
};
 
echo $file;

Cause analysis: because there is a notice error.

$file .= $ff;

The prototype is:

$file = $file.$ff;

The $file in the middle is not defined, and an error will be reported

Solution:

Option 1: Turn off the notice error of wamp Tip.

error_reporting(E_ALL & ~E_NOTICE);

Option 2: Define it in front$file=”;

The above is the detailed content of How to solve the problem that php images cannot be displayed due to errors. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn