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

Posted on 2006-04-03
Last Modified: 2010-04-06
Eg. $x = '';

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

How can I do that?
Question by:mnb93
    LVL 35

    Accepted Solution

    $wh = fopen( "uploads/2.jpg", "wb" ) ;
    fwrite( $wh, file_get_contents( "'" ) ) ;
    fclose( $wh ) ;

    *should* do it...

    I'm no PHP expert though :-(

    LVL 17

    Expert Comment

    That looks pretty good Tim, just that extra single quote at the end. The fwrite line should be:
    fwrite( $wh, file_get_contents( "" ) ) ;

    I tested it and it does work.  Don't underestimate urself Tim =)
    Joe P
    LVL 17

    Expert Comment

    Course it could be:
    $x = '';
    fwrite( $wh, file_get_contents($x) ) ;

    I'm guessing that is where the single quote came from, on a copy paste =)
    LVL 35

    Expert Comment


    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
    Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now