[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-windows
Subject:    RE: [PHP-WIN] PHP and Filesystem - Solution
From:       Fernando Madruga <FMadruga () ascoimbra ! pt>
Date:       2001-03-29 12:38:41
[Download RAW message or body]

Some lines were wrapped on my previous msg; this one fixes that, so you can
simply copy/paste the block of code into a file...

Bye,
  Madruga

-----Original Message-----
From: Fernando Madruga [mailto:FMadruga@ascoimbra.pt]
Sent: quinta-feira, 29 de Março de 2001 13:34
To: Thomas W. Badera; php-windows@lists.php.net
Subject: RE: [PHP-WIN] PHP and Filesystem - Solution


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
  // replace with your own path (DON'T END WITH SLASHES!!)
  $basepath = "d:\\lix";
  $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:
//    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

-- 
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

--
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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic