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

I am getting this error:

    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

This is the response code (please don't judge, I didn't write this, I have to live with it :/ ):

$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 and $fType are correct, so this is not the issue.

This is how I call the response:

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

When I use $field['fieldsrc'] (which looks something like this:

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

as a data for src inside image tag, the image is shown properly, so I am guessing the response is correct. Any idea what is wrong here?

readfile already outputs the content of the file. Remove the echo in front of it. It should be only

readfile($dataPath.'/'.$file);