Muflix
Muflix

Reputation: 6778

php function file_get_contents() gets only few KB of remote file

Hello i want to download remote zip, which is about 8 MB big. I wrote simple script

set_time_limit(0);
$zip = file_get_contents('http://web.tld/folder/download/getfile.do?filename=file.zip&_lang=Lang');
file_put_contents('zip_files/file.zip',$zip);

it works but stored file is not 8 MB but only 52 KB.

Its same if i use

set_time_limit(0);

$url  = 'http://web.tld/folder/download/getfile.do?filename=file.zip&_lang=Lang';
$path = 'zip_files/file.zip';

/* get and save remote data without exceeding php memory limit */
$fp = fopen($path, 'w');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp);
$data = curl_exec($ch);
curl_close($ch);
fclose($fp);

so maybe i have to use some stream option ?! Thank you

ps: i tried Snoopy library (http://sourceforge.net/projects/snoopy/) and its also same, only 52KB :P

include "libs/Snoopy-2.0/Snoopy.class.php";
$snoopy = new Snoopy;

$snoopy->submit($url);
print $snoopy->results;

Upvotes: 0

Views: 287

Answers (1)

Alexey Kurilov
Alexey Kurilov

Reputation: 438

Look inside saved file (use any text editor) it's possible to see not zip, just a page with wrong URL or something.

Upvotes: 1

Related Questions