note 2833 modified in filesize by ronabop

From: Date: Tue, 08 Aug 2000 20:23:56 +0000
Subject: note 2833 modified in filesize by ronabop
Groups: php.notes 
Request: Send a blank email to php-notes+get-712@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); http://www.php.net/manual/function.filesize.php

« previous php.notes (#712) next »