asmith Posted June 20, 2009 Share Posted June 20, 2009 Hi, What is the fastest way I could save the image example.com/image.jpg to my server? (or the script location) Quote Link to comment Share on other sites More sharing options...
thebadbad Posted June 20, 2009 Share Posted June 20, 2009 Something like this, if you have allow_url_fopen set to On: <?php ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 6.0; da; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11'); $url = 'http://example.com/image.jpg'; //save the remote file as 'image.jpg' in same directory as this script file_put_contents(basename($url), file_get_contents($url)); ?> I set the user agent string to bypass the check that some sites do. Quote Link to comment Share on other sites More sharing options...
asmith Posted June 20, 2009 Author Share Posted June 20, 2009 Thanks man. Thanks a lot My own code was this : <?php $url = 'http://example.com/image.jpg'; //save the remote file as 'image.jpg' in same directory as this script file_put_contents(basename($url), $url); ?> Dunno why I never thought I file_get first XD Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.