PHP to save external file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
monke
Forum Newbie
Posts: 2
Joined: Sun Oct 26, 2008 5:18 pm

PHP to save external file

Post 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.
nekoanz
Forum Newbie
Posts: 1
Joined: Mon Oct 27, 2008 4:36 am

Re: PHP to save external file

Post 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
monke
Forum Newbie
Posts: 2
Joined: Sun Oct 26, 2008 5:18 pm

Re: PHP to save external file

Post 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!
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: PHP to save external file

Post by onion2k »

copy() works with remote files if you've got fopen wrappers switched on.
Post Reply