Home >Backend Development >PHP Problem >What should I do if php cannot display the verification code image?

What should I do if php cannot display the verification code image?

藏色散人
藏色散人Original
2020-08-20 09:34:111573browse

The solution to the problem that php cannot display images is to add the code as [ob_clean(); header("Content-type:image/jpeg");] before the header output and save it.

What should I do if php cannot display the verification code image?

Recommended: "PHP Video Tutorial"

PHP verification code image cannot be displayed problem

I thought the gd2 library was not opened, but I checked with phpinfo and found that it was opened.

Solution

Add before the header output:

ob_clean(); //Key code to prevent the problem of 'the image cannot be displayed because of its own errors'.

header("Content-type:image/jpeg");

Example:

private function outPut() {
        ob_clean();  //关键代码,防止出现'图像因其本身有错无法显示'的问题。
        header('Content-type:image/png');
        imagepng($this->img);
        imagedestroy($this->img);
    }

The above is the detailed content of What should I do if php cannot display the verification code image?. 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