How can I download $x (a url) via PHP?

Eg. $x = 'http://www.google.com.au/intl/en_au/images/logo.gif';

I want the PHP script to download it and save it in the folder /uploads/

How can I do that?
LVL 5
mnb93Asked:
Who is Participating?
 
TimYatesCommented:
<?php
$wh = fopen( "uploads/2.jpg", "wb" ) ;
fwrite( $wh, file_get_contents( "http://www.google.com.au/intl/en_au/images/logo.gif'" ) ) ;
fclose( $wh ) ;
?>

*should* do it...

I'm no PHP expert though :-(

Tim
0
 
BogoJokerCommented:
That looks pretty good Tim, just that extra single quote at the end. The fwrite line should be:
fwrite( $wh, file_get_contents( "http://www.google.com.au/intl/en_au/images/logo.gif" ) ) ;

I tested it and it does work.  Don't underestimate urself Tim =)
Joe P
0
 
BogoJokerCommented:
Course it could be:
$x = 'http://www.google.com.au/intl/en_au/images/logo.gif';
fwrite( $wh, file_get_contents($x) ) ;

I'm guessing that is where the single quote came from, on a copy paste =)
0
 
TimYatesCommented:
:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.