We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

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

mnb93
mnb93 asked
on
Medium Priority
158 Views
Last Modified: 2010-04-06
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?
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2004
Commented:
<?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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
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
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 =)
CERTIFIED EXPERT
Top Expert 2004

Commented:
:-)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.