Downloading an image that is hotlink protected

admin

Administrator
Staff member
I would like to download an image that is hotlink protected. How can I forge the HTTP header with CURL to say the referer is coming from its own server?

I have tried with this command but it fails. I'm not familiar with PHP and help would be much apreciated.

Code:
curl -A "Mozilla/5.0" -L -b /tmp/c -c /tmp/c -s 'http://remote-site.com/image.jpg' > image.jpg

Option looks to be
Code:
CURLOPT_REFERER
with
Code:
curl_setopt
, or
Code:
curl --referer
but not sure about the correct syntax.

<hr>

EDIT 2 :

I got an error saying that curl_setopt() expects parameter 2 to be long. After removing the MUTE option the error is gone.

To show the image I have tried this code but the page remains blank.

Code:
$image = curl_exec($ch);
curl_close($ch);
fclose($fp);
print '&lt;img src="'.$image.'"/&gt;';

<hr>

EDIT 1:

The code I have entered in my Wordpress post (I use the plugin <a href="http://www.willmaster.com/software/WPplugins/insert-php-wordpress-plugin-instructions.php" rel="nofollow">Insert PHP</a>)

Code:
[insert_php]

curl --referer http://www.DOMAIN.com/ -A "Mozilla/5.0" -L -b /tmp -c /tmp -s 'http://www.DOMAIN.com/image.png' &gt; image.png

[/insert_php]

The error I have when I load the page :

Code:
Parse error: syntax error, unexpected ‘&lt;‘ in /public_html/wp-content/plugins/insert-php/insert_php.php(48) : eval()’d code on line 8