Posted By

Tamedo on 12/06/08


Tagged


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

ginoplusio
luman
bryandease
IMPGTX


php copy file to locathost from remote server


 / Published in: PHP
 

  1. //original image
  2. $img = "http://www.site.com/blah.gif";
  3.  
  4. //directory to copy to (must be CHMOD to 777)
  5. $copydir = "/home/user/public_html/directory/";
  6.  
  7. $data = file_get_contents($img);
  8. $file = fopen($copydir . "blah.gif", "w+");
  9. fputs($file, $data);
  10. fclose($file);

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: youdontmeanmuch on December 21, 2008

$removefile = "http://www.site.com/blah.gif"; $localfile = "./blah.gif";

$data = filegetcontents($removefile); fileputcontents($localfile, $data);

Posted By: edwin on June 7, 2009

Useful script, but how about stripping the filename and using that instead of blah.gif? like: 3. $fname= basename($img); and replace '8' by:

$file = fopen($copydir . $fname, "w+");

so full code will be:

//original image $img = "http://www.site.com/blah.gif.JPG"; $fname= basename($img); echo $fname; //directory to copy to (must be CHMOD to 777) $copydir = "/var/www/upload/"; $data = filegetcontents($img);
$file = fopen($copydir . $fname, "w+"); fputs($file, $data); fclose($file);

Posted By: edwin on June 7, 2009

Apparently I have trouble putting the code in properly so here goes again:

//original image $img = "http://www.site.com/blah.gif.JPG"; $fname= basename($img);
//directory to copy to (must be CHMOD to 777) $copydir = "/var/www/upload/"; $data = filegetcontents($img); $file = fopen($copydir . $fname, "w+"); fputs($file, $data); fclose($file);

Posted By: edwin on June 7, 2009

I apologize but this is the first ever comment I put here and already I am screwing up. Here goes again

//original image

$img = "http://www.site.com/blah.gif";

$fname= basename($img);

//directory to copy to (must be CHMOD to 777)

$copydir = "/var/www/upload/";

$data = filegetcontents($img); $file = fopen($copydir . $fname, "w+");

fputs($file, $data);

fclose($file);

You need to login to post a comment.