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) Link to comment https://forums.phpfreaks.com/topic/163010-solved-get-an-image-or-file-from-other-serversite/ 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. Link to comment https://forums.phpfreaks.com/topic/163010-solved-get-an-image-or-file-from-other-serversite/#findComment-860103 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 Link to comment https://forums.phpfreaks.com/topic/163010-solved-get-an-image-or-file-from-other-serversite/#findComment-860110 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.