Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP显示标题已断开的图像_Php_Image_Header - Fatal编程技术网

PHP显示标题已断开的图像

PHP显示标题已断开的图像,php,image,header,Php,Image,Header,我试图显示要在标记中使用的图像,但此代码显示的图像已损坏。我知道文件存在(查看文件是否存在行),我得到了一个文件大小,并且内容类型设置正确。有人能看到我遗漏了什么吗 $image_path = "../../../uploads/theimage.jpg"; $image_info = pathinfo($image_path); $image_ext = $image_info["extension"]; switch( $image_ext ) { case "gif":

我试图显示要在
标记中使用的图像,但此代码显示的图像已损坏。我知道文件存在(查看文件是否存在行),我得到了一个文件大小,并且内容类型设置正确。有人能看到我遗漏了什么吗

$image_path = "../../../uploads/theimage.jpg";

$image_info = pathinfo($image_path);

$image_ext = $image_info["extension"];

switch( $image_ext ) {
    case "gif": 
        $content_type="image/gif"; 
        break;
    case "png": 
        $content_type="image/png"; 
        break;
    case "jpeg":
    case "jpg": 
        $content_type="image/jpeg"; 
        break;
    default:
        die("invalid image type");
        break;
}

if (file_exists($image_path)) {
    header('Content-Type:'.$content_type);
    header('Content-Length: ' . filesize($image_path));

    echo file_get_contents($image_path);
} else {
    echo 'no file?';
}

我尝试过使用Yup而不是
file\u get\u contents
是的,但运气不好。如果你查看“页面”/损坏图像的来源,你会看到什么?它不会让我看到,因为它认为它是一个图像。我不知道它是否会显示任何有意义的内容,但如果你注释掉内容类型行,它会让你看到