[eluser]taewoo[/eluser]
Hi all.
I've written app that generates a zip file of json file (the file is HUGE, thus to save time d/l'ing) that another server downloads, unzip, and reads.
The server that downloads the zip has this code:
Code:
function saveRemoteFile($remote_file, $local_file)
{
$handle = @fopen($remote_file, "r");
if(!$handle)
{
throw new Exception("Can't retrieve $remote_file");
}
$out_handle = fopen($local_file, "w+");
if(!$out_handle)
{
throw new Exception("Can't open $local_file for write");
}
while (!feof($handle))
{
$binary_line=fread($handle, 8192);
fwrite($out_handle, $binary_line, 8192);
}
fclose($handle);
fclose($out_handle);
}
This is the helper function i've written... and this doesn't seem to work in a sense that it's padding the downloaded zip file with erroneous characters. If i run "unzip data.zip", the command line error I get is
Code:
Archive: data.zip
warning [data.zip]: 265 extra bytes at beginning or within zipfile
(attempting to process anyway)
inflating: data.txt
If I try to unzip this file with PHP:
Code:
$zip = zip_open("data.zip");
if (is_resource($zip)) {
echo "OK";
while ($zip_entry = zip_read($zip)) {
echo $zip_entry."\n";
if (zip_entry_open($zip, $zip_entry, "r")) {
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
echo $buf;
zip_entry_close($zip_entry);
}
}
zip_close($zip);
}
.... the WHILE loop does not execute.
If I do a "wget" to retrieve the file, i don't have any problems, which concludes me to think that it's fwrite that's causing the problem.
Any thoughts on this?