php file download question

Discussion in 'PHP' started by LaPoChE, Jul 26, 2006.

  1. #1
    Hey,

    Is there a way in PHP the i can download a .zip file from another site?

    thanks
     
    LaPoChE, Jul 26, 2006 IP
  2. tflight

    tflight Peon

    Messages:
    617
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Depending on any restrictions your host might have placed within your copy of PHP you can normally use fopen.
     $handle = fopen("http://www.example.com/file.zip", "r");
    
    PHP:
     
    tflight, Jul 26, 2006 IP
  3. coderlinks

    coderlinks Peon

    Messages:
    282
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Or try using cURL in binary mode.

    
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,"http://www.foobar.com/foo.zip");
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_BINARYTRANSFER,1);
    curl_setopt($ch,CURLOPT_HEADER,0);
    $output = curl_exec($ch);
    $len = curl_getinfo($ch,CURLINFO_SIZE_DOWNLOAD);
    $fp = fopen("foo.zip","wb");
    fwrite($fp,$output,$len);
    fclose($fp);
    
    PHP:
    Now the file foo.zip should be on your server.

    Or try these scripts.
    http://www.rapidleech.com/ : Originally made for file-sharing services. but can be used for normal HTTP downloads. Has a cool interface with a progress bar and all that.

    http://noveis.net/filesnatcher

    Thomas
     
    coderlinks, Jul 27, 2006 IP