<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Comments on snippet: 'php copy file to locathost from remote server'</title>
<link>http://snipplr.com</link>
<description>Snipplr comments feed'</description>
<language>en-us</language>
<pubDate>Wed, 22 May 2013 14:41:14 GMT</pubDate>
<item>
<title>edwin said on 6/7/09</title>
<link>http://snipplr.com/view/10306/php-copy-file-to-locathost-from-remote-server/</link>
<description><![CDATA[ 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); ]]></description>
<pubDate>Sun, 07 Jun 2009 05:36:52 GMT</pubDate>
<guid>http://snipplr.com/view/10306/php-copy-file-to-locathost-from-remote-server/</guid>
</item>
<item>
<title>edwin said on 6/7/09</title>
<link>http://snipplr.com/view/10306/php-copy-file-to-locathost-from-remote-server/</link>
<description><![CDATA[ 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); ]]></description>
<pubDate>Sun, 07 Jun 2009 05:34:45 GMT</pubDate>
<guid>http://snipplr.com/view/10306/php-copy-file-to-locathost-from-remote-server/</guid>
</item>
<item>
<title>edwin said on 6/7/09</title>
<link>http://snipplr.com/view/10306/php-copy-file-to-locathost-from-remote-server/</link>
<description><![CDATA[ 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 = file_get_contents($img);  
$file = fopen($copydir . $fname, "w+");
fputs($file, $data); 
fclose($file); ]]></description>
<pubDate>Sun, 07 Jun 2009 05:32:14 GMT</pubDate>
<guid>http://snipplr.com/view/10306/php-copy-file-to-locathost-from-remote-server/</guid>
</item>
<item>
<title>youdontmeanmuch said on 12/21/08</title>
<link>http://snipplr.com/view/10306/php-copy-file-to-locathost-from-remote-server/</link>
<description><![CDATA[ $remove_file = "http://www.site.com/blah.gif";
$local_file = "./blah.gif";

$data = file_get_contents($remove_file);
file_put_contents($local_file, $data); ]]></description>
<pubDate>Sun, 21 Dec 2008 10:30:34 GMT</pubDate>
<guid>http://snipplr.com/view/10306/php-copy-file-to-locathost-from-remote-server/</guid>
</item>
</channel>
</rss>