how to copy an image URL from a form to your own 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
bobafart
Forum Newbie
Posts: 8
Joined: Thu Feb 28, 2008 2:31 pm

how to copy an image URL from a form to your own server??

Post by bobafart »

I am trying to copy an image that the user inputs into a form to a local copy on my server.. and for security reasons rename the file

so basically, user inputs a URL to the image (http://www.foo.com/image.gif)
user hits submit
script copies http://www.foo.com/image.gif and renames it to a random md5 name

how would I do this using PHP?
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: how to copy an image URL from a form to your own server??

Post by Kieran Huggins »

use http://php.net/file_get_contents to grab the file.

also, why not name the file it's own md5() instead of a random one? That way you get the added benefit of saving storage space when there's a collision ;-)
bobafart
Forum Newbie
Posts: 8
Joined: Thu Feb 28, 2008 2:31 pm

Re: how to copy an image URL from a form to your own server??

Post by bobafart »

my host doesn't allow me to use fopen() so I cant use your solution

any other ideas?
User avatar
Sekka
Forum Commoner
Posts: 91
Joined: Mon Feb 18, 2008 10:25 am
Location: Huddersfield, West Yorkshire, UK

Re: how to copy an image URL from a form to your own server??

Post by Sekka »

I have just been talking about this in another thread.

From what I understand, fopen() is the only way to do this.
Post Reply