PHP - 警告:getimagesize无法打开流:HTTP请求失败

时间:2016-12-14 14:55:52

标签: php

我收到此错误:

    Warning: getimagesize(http://dev.clearcaresolutions.local/viewimage.php?file=screenshot_from_2016-11-29_12-12-06.png&type=form): 
failed to open stream: HTTP request failed! HTTP/1.0 
500 Internal 
Server Error in /var/www/vhosts/dev.clearcaresolutions.local/current/modules/tasks/edit_log.php on line 845

这是回复代码(请不要判断,我没有写这个,我必须忍受它:/):

$fSize = filesize($dataPath.'/'.$file);
$fType = cFile::getMimeType($file);

    // write the HTML headers
    header ("X-Frame-Options: sameorigin");
    #header("X-Frame-Options: deny");                                           # on
    header ("X-XSS-Protection: 1; mode=block");                                 # off
    header ("X-Content-Type-Options: nosniff");                                 # on
    // BEGIN extra headers to resolve IE caching bug (JRP 9 Feb 2003)
    header("Pragma: ");                                                         # on
    header("Cache-Control: ");                                                  # on
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");                           # on
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");              # on
    header("Cache-Control: no-store, no-cache, must-revalidate");  //HTTP/1.1   # on
    header("Cache-Control: post-check=0, pre-check=0", false);                  # on
    // END extra headers to resolve IE caching bug

    header("MIME-Version: 1.0");
    header("Content-Description: File Transfer");
    header("Content-Length: {$fSize}");                                         # ---
    header("Content-Type: {$fType}");                                           # on
    header("Content-Transfer-Encoding: binary");                                # ---
    header("Content-disposition: {$mode}; filename={$file}");                   # on
    echo readfile($dataPath.'/'.$file);

$ fSize $ fType 是正确的,所以这不是问题。

这就是我所说的回应:

$protocol = stripos($_SERVER['SERVER_PROTOCOL'],'https') === true ? 'https://' : 'http://';
(line 845) list($width, $height) = getimagesize($protocol.$_SERVER['SERVER_NAME'].$field['fieldsrc']);

当我使用 $ field [' fieldsrc'] 时(看起来像这样:

/viewimage.php?file=screenshot_from_2016-11-29_12-12-06.png&type=form

作为 src 内部图片标记的数据,图像显示正确,所以我猜测响应是正确的。知道这里有什么问题吗?

1 个答案:

答案 0 :(得分:0)

readfile已经输出了文件的内容。去除它前面的回声。它应该只是

readfile($dataPath.'/'.$file);
相关问题