/ Published in: PHP
Expand |
Embed | Plain Text
function cache_image($image_url){ //replace with your cache directory $image_path = 'path/to/cache/dir/'; //get the name of the file //make sure its an image if($extension=="gif"||$extension=="jpg"||$extension=="png"){ //get the remote image //save it } } //usage //cache_image("http://www.flickr.com/someimage.jpg");
Comments
Subscribe to comments
You need to login to post a comment.

Good piece of code. As an addition I would add a strtolower for the extension, so the comparision is the same no matter if the extension is PNG, pNg, PnG or png. Also you could overwrite two images, say you get "domain1.com/test.jpg"and then "someotherdomain.com/test.jpg" the test.jpg would be overwritten. Alternative, you could save it with a has of the url, making it easy to handle. Like make an sha hash out of the image_url variable and save the image under that name. If you need it again, you can search the same way for it and never overwrite it again.