Hi all, i m trying to download a jpg file from a remote http host, i can download the file.. the problem is to strip the headers and write just the file to disk.. anyone can help me with this? here is my code:
$fp = fsockopen("www.fr.xgn.com.br", 80, $errno, $errstr, 30);
if (!$fp) {
echo "Error: $errstr ($errno)<br \>\n";
} else {
fputs($fp, "GET /img/4237c9c4e7f0a.jpg HTTP/1.0\r\nHost: www.fr.xgn.com.br\r\n\r\n");
while (!feof($fp)) {
$buffer .= fgets($fp);
}
fclose($fp);
# preg_match('/Content-Length: ([0-9]+)/', $buffer, $parts);
# $final = substr($buffer,-$parts[1]);
# print_r($parts);
if($destino = fopen("image.jpg", "w+")) {
if(fwrite($destino,$buffer)) {
echo "File saved!";
} else {
echo "Cannot write to file!";
}
} else {
echo "Cannot create file!";
}
}
Using it this way, it outputs like this:
HTTP/1.0 200 OK
Age: 61296
Accept-Ranges: bytes
Date: Thu, 02 Feb 2006 01:29:34 GMT
Content-Length: 29474
Content-Type: image/jpeg
Server: Apache/1.3.33 (Unix) mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 PHP/4.3.11 FrontPage/5.0.2.2635 mod_ssl/2.8.22 OpenSSL/0.9.7a
Last-Modified: Wed, 16 Mar 2005 05:53:08 GMT
ETag: "63c340-7322-4237c9c4"
ÿØÿà JFIF ÿþ >CREATOR: gd-jpeg v1.0 (using IJG JPEG v62),
I want to strip those stupid headers.. any ideas? I tryied to using the Content-Lenght (look at the commented lines) but that cut the beggining of the jpg file with the headers.. so i m out of ideas 🙁