Save a file from another server

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
User avatar
jwalsh
Forum Contributor
Posts: 202
Joined: Sat Jan 03, 2004 4:55 pm
Location: Cleveland, OH

Save a file from another server

Post by jwalsh »

Hey guys,

We've written an RSS import feed which takes a given rss feed, strips most tags, except links, images, and a few other things.

We have an issue with images. We can link to the existing file on someone elses server just fine, but to avoid being a bandwidth theif, I'd like to download that image to our server, and link to it locally.

Any ideas how I can do this download transfer? Something with sockets I assume?

Thanks,

Josh
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

file_get_contents('http://the file')
fopen()-fwrite()-fclose()
str_replace() the original url with your now internalized copy.
User avatar
jwalsh
Forum Contributor
Posts: 202
Joined: Sat Jan 03, 2004 4:55 pm
Location: Cleveland, OH

Post by jwalsh »

Much easier than I thought, works like a charm.

Feyd, you never cease to amaze.
Post Reply