Jump to content

[SOLVED] get an image or file from other server(site)


asmith

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.