Re: Can PHP be used to snatch images cross-domain?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2008-12-16 at 21:29 -0500, Rob Gould wrote:
> If I have a php script on my own server, can it be used to snatch a JPEG image off of another server on a different domain and upload it to my server?  For example, could I provide an URL to an image on another server and a path on my own server in which to place it?  I know in the world of Ajax, I could run into cross-domain security issues, but I'm wondering if I can get around that with PHP.
> 

Yes, this can be done quite easily.

<?php

    $content = file_get_contents( 'http://www.foo.com/images/foo.png' );
    file_put_contents( '/tmp/foo.png', $content );

?>

You will need fopen wrappers enabled for this to work. Either way, there
are other ways to skin the cat if fopen wrappers cannot be enabled.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux