Retrieving an image from a URL
Moderator: General Moderators
Retrieving an image from a URL
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.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
[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.
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.