RE: [PHP-WIN] PHP and Filesystem - Solution

From: Date: Thu, 29 Mar 2001 12:33:39 +0000
Subject: RE: [PHP-WIN] PHP and Filesystem - Solution
Groups: php.windows 
Request: Send a blank email to php-windows+get-6366@lists.php.net to get a copy of this message
First, if you're trying to get just the name of a file in a url, use basename(). Then remove stripslahes as it corrupts binary data. This would result in the following code that I've *TESTED* with some image urls and modified to print a nicely formated progress; I've also renamed some variables... <?php $basepath = "d:\\lix"; // replace with your own path (DON'T END WITH SLASHES!!) $flist = fopen( "$basepath\\images.txt", "r" ) or die( "Unable to find images.txt!\n" ); while( !feof( $flist ) ) { $url = trim( fgets( $flist, 4096 ) ); // I don't know WHY you would want to compare $url to 'Navigation', but I've kept it... // If it's not needed, replace the 'if' line with the following one: // if ( $url ) { // ignore empty lines... if ( $url && $url != "Navigation" ) { $fn = "$basepath\\images\\" . basename( $url ); echo "Copying $url\n => $fn\n "; $foutput = fopen( $fn, "wb" ); $fgrab = fopen( $url, "rb" ); // "r" also seems to work... $kb = 0; while( !feof($fgrab) ) { $grabbed = fread( $fgrab, 1024 ); $kb++; if ( ( $kb % 10 ) == 0 ) { echo "*"; // write an asterisk for every 10 KB grabbed... } else { echo "."; // write a dot for each KB grabbed... }; fwrite( $foutput, $grabbed, strlen( $grabbed ) ); }; echo "\n"; // ready output for next url... fclose( $foutput ); fclose( $fgrab ); }; }; fclose( $flist ); ?> -----Original Message----- From: Thomas W. Badera [mailto:twb@vonx.com] Sent: quarta-feira, 28 de Março de 2001 17:20 To: php-windows@lists.php.net Subject: [PHP-WIN] PHP and Filesystem Another question.... I've got a script that is supposed to read URLs out of a text file, open the image at the URL, then copy it to the local computer. The code follows: <?php $input = fopen("d:\\webs\\sportspotonline.com\\data\\images.txt", "r"); while (!feof($input) { $buffer = trim(fgets($input, 4096)); if ($buffer != "Navigation") { $fnArray = explode("/", $buffer); $fn = $fnArray[sizeof($fnArray)-1]; $fn = "d:\\webs\\sportspotonline.com\\data\\images\\".$fn; $output = fopen($fn, "wb"); $grab = fopen($buffer, "rb"); while ($grabbed = fread($grab, 4096);) { $grabbed = stripslashes($grabbed); fwrite($output, $grabbed, strlen($grabbed)); } fclose($output); fclose($grab); } } fclose($input); ?> The images this saves are all corrupt.... openable, partially viewable, but corrupt. Any idea? --TWB --- Thomas W. Badera WebTeam Manager Clarkson University < baderatw@clarkson.edu > -- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-windows-unsubscribe@lists.php.net For additional commands, e-mail: php-windows-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.windows (#6366) next »