Return to Snippet

Revision: 46155
at May 13, 2011 18:35 by zayyarphone


Initial Code
function image_download($file_source, $file_target)
{
      // prepare
      $file_source = str_replace(' ', '%20', html_entity_decode($file_source)); // fix url format
      if (file_exists($file_target)) chmod($file_target, 0777); // add write permission

      // opne files
      if (($rh = fopen($file_source, 'rb')) === FALSE) return false; // fopen() handles
      if (($wh = fopen($file_target, 'wb')) === FALSE) return false; // error messages.

      // read & write
      while (!feof($rh))
      {
            if (fwrite($wh, fread($rh, 1024)) === FALSE)
            {
                  // unable to write to file, possibly
                  // because the harddrive has filled up
                  fclose($rh);
                  fclose($wh);
                  return false;
            }
      }

      // close files
      fclose($rh);
      fclose($wh);
      return true;
}

Initial URL

                                

Initial Description

                                

Initial Title
php image download

Initial Tags
php, image, download

Initial Language
PHP