Activity Stream
48,167 MEMBERS
6890 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 7 of 7
  1.     
    #1
    The Wise One
    Website's:
    twilight.ws ddlrank.com

    Default [PHP] Downloading a file with cURL

    This thread is both a code snippet and a question.

    Lets start with the code:
    PHP Code: 
    $url "http://downloadwebsite.com/file_you_are_going_to_download.rar";
    $out fopen("./".trim(basename($url)), 'wb+'); //Opens the temp file in the local directory of your server, same filename as the file you are downloading
    $ch curl_init(); //initialize curl 
    curl_setopt($chCURLOPT_FILE$out);  //Set it to download the content to the file created previously
    curl_setopt($chCURLOPT_HEADER0); //Depending on the website you are downloading from there are headers that need to be sent
    curl_setopt($chCURLOPT_URL$url); //Set the url you want to start curling :P
    curl_exec($ch); //Do the magic
    curl_close($ch); //Close the magic
    fclose($out); //Close the downloaded file properly 
    Now an issue:
    On a server from a KWWH member this worked perfectly, but now all of a sudden, instead of downloading the file to the server, it displays the contents of the file in the browser, any ideas why this is happening?

    Thanks all
    Whoo Reviewed by Whoo on . [PHP] Downloading a file with cURL This thread is both a code snippet and a question. Lets start with the code: $url = "http://downloadwebsite.com/file_you_are_going_to_download.rar"; $out = fopen("./".trim(basename($url)), 'wb+'); //Opens the temp file in the local directory of your server, same filename as the file you are downloading $ch = curl_init(); //initialize curl curl_setopt($ch, CURLOPT_FILE, $out); //Set it to download the content to the file created previously curl_setopt($ch, CURLOPT_HEADER, 0); Rating: 5
    I can always be contacted by sending a tweet @twilightws

  2.   Sponsored Links

  3.     
    #2
    Respected Member
    Website's:
    GraffThe.Net MCSkatty.com MCSkatty.co.uk MCSkatty.net MCSkatty.org MCSkatty.info
    Does he have ArchView Installed & activated ?!
    GraffThe.Net - The #1 Graffiti Download Site.



  4.     
    #3
    Respected Member
    So the file is to be downloaded to a member and not on the server. Correct?

    If yes then maybe the member has changed the way his browser is handling the rar type file.

  5.     
    #4
    The Wise One
    Website's:
    twilight.ws ddlrank.com
    Quote Originally Posted by Lock Down View Post
    So the file is to be downloaded to a member and not on the server. Correct?

    If yes then maybe the member has changed the way his browser is handling the rar type file.
    No, the file is to be stored on the server:

    PHP Code: 
    $out fopen("./".trim(basename($url)), 'wb+'); //Opens the temp file in the local directory of your server, same filename as the file you are downloading 
    </span></span>
    I can always be contacted by sending a tweet @twilightws

  6.     
    #5
    Respected Developer
    try this
    PHP Code: 
    $url "http://downloadwebsite.com/file_you_are_going_to_download.rar";
    $out fopen("./".trim(basename($url)), 'wb+');
    $ch curl_init($url);
    curl_setopt($chCURLOPT_FILE$out);
    curl_exec($ch);
    curl_close($ch);
    fclose($out); 
    Bots Development | Web Development | Wordpress Customization | PSD Conversion

    Life has many twists and turns in it, you have to take what you are given and use it for the best.

  7.     
    #6
    Respected Member
    I have read that you must use CURLOPT_RETURNTRANSFER ,1 when doing it that way. Otherwise it sends it to the browser.

    I never use it that way myself. I always use fopen to get the remote file , read and save it.

  8.     
    #7
    The Wise One
    Website's:
    twilight.ws ddlrank.com
    Hi,

    Thanks for both suggestions, haven't been able to try it out yet because the person having the issue just switched server and hasn't reported back to me.

    Thanks for the efforts thought.
    I can always be contacted by sending a tweet @twilightws

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. downloading from file hosting links with FTP?
    By Mitt281 in forum Web Application/Script Support
    Replies: 1
    Last Post: 7th Nov 2012, 05:43 AM
  2. Curl url file (I need help)
    By spanero in forum Web Development Area
    Replies: 3
    Last Post: 22nd Dec 2011, 04:23 PM
  3. Looking for: HTTP File Downloading script
    By CuraHack in forum Web Development Area
    Replies: 4
    Last Post: 12th Apr 2011, 03:33 AM
  4. Replies: 25
    Last Post: 11th Apr 2011, 08:07 AM
  5. Cant visit my home while downloading a file vps(kloxo)
    By dark_horse in forum Server Management
    Replies: 5
    Last Post: 26th Jan 2011, 12:13 AM

Tags for this Thread

BE SOCIAL