Page 1 of 1

PHP to save external file

Posted: Mon Oct 27, 2008 4:08 am
by monke
I've been trying to find some help with a php script that allows a user to enter a URL and pulls a file (a single JPG) by matching it with a regular expression, saving it to the local server. Our previous programmer wrote the original script in Perl and used wget to do this - is there a simple way of doing it in PHP? I appreciate any and all advice.

Re: PHP to save external file

Posted: Mon Oct 27, 2008 4:37 am
by nekoanz
you can use the move_uploaded_file() function...

the syntax is simple you just need to specify the source URl then the destination URL

then the file will be copied

Re: PHP to save external file

Posted: Mon Oct 27, 2008 5:20 am
by monke
From the examples it looks like this can only be used with files that are currently on the server already. Can this be used to save a file from a different (remote) server? For instance, my current script is on domain1.com and I would like to save the image I have at domain2.com/image2.jpg.

Thanks for the quick response!

Re: PHP to save external file

Posted: Mon Oct 27, 2008 5:46 am
by onion2k
copy() works with remote files if you've got fopen wrappers switched on.