Copy remote files with copy() function

Seven years old comment in PHP manual, which still shines like a real gem! You can use copy() function to easily (one-liner!) copy remote files, without doing messy fopen() stuff:

[code language=”php”]
if(!@copy(‘http://someserver.com/somefile.zip’,’./somefile.zip’))
{
$errors= error_get_last();
echo "COPY ERROR: ".$errors[‘type’];
echo "<br />\n".$errors[‘message’];
} else {
echo "File copied from remote!";
}
[/code]

steve a h, whoever you’re or were, I salute you!

Leave a Reply