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

2008-12-17 Thread Jan Kaštánek
Chris:
>
> curl can handle timeouts much better (file_get_contents will timeout when
> the server on the other end says so).

If you use stream context, you can set timeout to file_get_contents() as well.

-- 
toby

http://toby.cz/

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



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

2008-12-16 Thread Chris

Rob Gould wrote:

Brilliant!

Now why do all these other scripts I've found make it look so hard??

http://wiki.dreamhost.com/index.php/CURL


curl can handle timeouts much better (file_get_contents will timeout 
when the server on the other end says so). it can also tell you if a 404 
is returned, and handle basic authentication.


file_get_contents is very simple. if i replace foo.png with a 404 page, 
that's what you'll get - and that's what you'll save as your image.


--
Postgresql & php tutorials
http://www.designmagick.com/


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



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

2008-12-16 Thread Rob Gould
Brilliant!

Now why do all these other scripts I've found make it look so hard??

http://wiki.dreamhost.com/index.php/CURL

Take a look at the last script on that site.  I suppose it's because of all the 
error-handling.  That last "downloader class" looks promising, through I'm not 
sure how to pass an URL into it to get and save to a special directory on my 
server.  I like your example better.


 
On Tuesday, December 16, 2008, at 09:41PM, "Robert Cummings" 
 wrote:
>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.
>
>
>$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



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

2008-12-16 Thread Robert Cummings
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.

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



[PHP] Can PHP be used to snatch images cross-domain?

2008-12-16 Thread Rob Gould
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.

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