PHP - Warning: getimagesize failed to open stream: HTTP request failed
<p>I am getting this error:</p>

<pre><code>    Warning: getimagesize(http://dev.clearcaresolutions.local/viewimage.php?file=screenshot_from_2016-11-29_12-12-06.png&amp;amp;amp;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
</code></pre>

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

<pre><code>$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);
</code></pre>

<p><strong>$fSize</strong> and <strong>$fType</strong> are correct, so this is not the issue.</p>

<p>This is how I call the response:</p>

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

<p>When I use <strong>$field['fieldsrc']</strong> (which looks something like this: </p>

<pre><code>/viewimage.php?file=screenshot_from_2016-11-29_12-12-06.png&amp;type=form
</code></pre>

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