Home  >  Article  >  Backend Development  >  Solution to why php cannot display images

Solution to why php cannot display images

藏色散人
藏色散人Original
2020-11-20 10:04:155373browse

php cannot display images because there are other outputs in the source code besides img output. The solution is to cancel any output before the header is called.

Solution to why php cannot display images

Recommended: "PHP Video Tutorial"

Specific questions:

php files can output pictures but cannot display them!

Use

imagegif($image,'verify.php');
echo Solution to why php cannot display images;

to output pictures.

But changing it to

header ( "content-type:image/gif" );
imagegif($image);

can output pictures. But it can't be displayed. There are no errors in the file.

How can I display it? . . .

Solved. Add ob_end_clean();

in the first line.

Solution to why php cannot display images

##Solution:

After testing Both methods can be displayed correctly. It is estimated that the reason why your second method cannot be displayed normally is:

In the second method, in addition to the img output, there are other outputs.

Please refer to the sample code below:

Why the second method cannot have content in front of the header. To find out the reason, please refer to the following explanation:

Header() must be called before any actual output, whether it is an ordinary html tag, a blank line or space in a file, or a blank line or space in a PHP file.

Simple sentence: If there is output before header() is called, an error will occur.

The above is the detailed content of Solution to why php cannot display images. 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
Previous article:How to modify xml in phpNext article:How to modify xml in php