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.
Recommended: "PHP Video Tutorial"
Specific questions:
php files can output pictures but cannot display them!
Use
imagegif($image,'verify.php'); echo <img scr=‘verify.php’/ alt="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:
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:<?php // 创建新的图像实例 $im = imagecreatetruecolor(100, 100); // 设置背景为白色 imagefilledrectangle($im, 0, 0, 99, 99, 0xFFFFFF); //在图像上写字 imagestring($im, 3, 40, 20, 'GD Library', 0xFFBA00); //echo "这一行如果加上就不能正常显示下面的图像了。"; // 输出图像到浏览器 header('Content-Type: image/gif'); imagegif($im); imagedestroy($im); ?>
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!