Hello,
I'm using this code to read a binary file:
function GetContent($sHost, $nPort, $sPath)
{
set_magic_quotes_runtime(0);
$fp = fsockopen($sHost, $nPort, $errno, $errstr, 30);
$sContent = '';
if (!$fp)
{
echo "$errstr ($errno)<br />\n";
}
else
{
$out = "GET $sPath HTTP/1.0\r\n";
$out .= "Host: $sHost\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp))
{
$sContent .= fread($fp, 8192);
}
fclose($fp);
}
return $sContent;
}
I was happy when this code have read a GIF and a JPG file successfully. Then tried with other files and I found that the code reads only about 10% of the files.
For other GIF and JPG files, the file is opened, but feof becomes true immediately. The WWW server is IIS 5.0, the files are in the same directory and their permissions seem to be the same. I checked the contents of the files, all of them contain zeros, including the files read successfully.
It seems that the problem is with small (<1000 bytes) files. Tried to change the buffer size from 16 to 16384, no success.
Any idea?