Page 1 of 1
Retrieving an image from a URL
Posted: Fri Oct 15, 2004 2:23 am
by ShatterX
I have a forum where users can upload images that they have created, however some of them have been just putting in URL's to images that they have created instead of going through the upload process. The problem this creates is if their site goes down or otherwise goes offline I end up with broken links. I would like someone to point me in the right direction for creating a script that reads the URL they put in with an image tag and actually goes out and retrieves that image and stores it on our servers locally. Any help would be greatly appreciated as I am a novice PHP user and just inherited this can of worms.
Posted: Fri Oct 15, 2004 3:13 am
by mudkicker
Just an idea but i don't know is there any more fficient way to do it. You can fopen() the url in binary mode save it as a file. Then move it to desired folder. IT's abasic way.
Posted: Sun Oct 17, 2004 7:39 pm
by feyd
[php_man]file_get_contents[/php_man]() and [php_man]fopen[/php_man]() can be easily used (if you have File URL Wrappers on).
If you do not, then you may need to use [php_man]curl[/php_man] or [php_man]fsockopen[/php_man] if those are available.
Saving the file onto the server, then checking it to make sure it's in fact an image (using [php_man]getimagesize[/php_man]()) is the general way I've done things like this.