note 2833 deleted from function.filesize by jimw
| From: | jimw@php.net | Date: | Fri, 14 Dec 2001 20:14:13 +0000 |
| Subject: | note 2833 deleted from function.filesize by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-22705@lists.php.net to get a copy of this message | ||
here is some sample code to retrieve the size of an image and then save the image to disk, from a
web server.
$imgDir = "/home/httpd/upload/new.gif"; // save new gif here
$imgPath = '/foo/bar.gif'; // remote location
$imgHost = "www.foo.com";
$fp = fsockopen($imgHost, 80, &$errno, &$errstr, 30);
if(!$fp) {
echo "ERROR: $errno: $errstr";
} else {
fputs($fp,"HEAD $imgPath HTTP/1.0\nHost: $imgHost\n\n");
while(!feof($fp)) {
$response .= fgets($fp,128);
}
fclose($fp);
}
$imgSz = ereg_replace("(.*)(Content-Length: )([0-9]*)(.*)","\\3",$response);
$file = fopen($imgPath,"br"); // open external gif in binary mode and RO
$contents = fread( $file, $imgSz );
fclose($file);
$file2 = fopen($imgDir,"wb"); // open new local file in bin/write mode
fwrite($file2,$contents,$imgSz);
fclose($file2);