Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 132
  • Last Modified:

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?
0
mnb93
Asked:
mnb93
  • 2
  • 2
1 Solution
 
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now