Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2001
    Location
    Cedar Falls, IA
    Posts
    54

    wget type method in php?

    I am trying to download a zip file from a remote host in php. I want to try and not use exec(wget) as I want this to work with php not just php on linux w/ wget installed. I have searched google, php.net, etc and have not really found anything to get a file. Thanks for your help!

    wade

  2. #2
    PHP Code:
    $fp fopen ('the file you want to download''r');
    while (
    false !== ($i fgetc ($fp)))
    $file .= $i;

    $fp fopen ('name of the file locally''w');
    fwrite ($fp$file); 
    This should work. =)

    Edit: Why aren't my PHP tags working? Nvm. =)
    Last edited by Kijit Solutions; 08-01-2005 at 03:27 PM.

  3. #3
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,099
    You need to use cURL for this.
    In order to understand recursion, one must first understand recursion.
    If you feel like it, you can read my blog
    Signal > Noise

  4. #4
    Join Date
    Nov 2001
    Location
    Cedar Falls, IA
    Posts
    54
    Great! That worked to get the file. Is there a way that I can output the percentage until complete as the file is downloading? It is a zip file that is 14Mb and based on some hosting accounts it may take a bit to download.

    PHP Code:
    $ch curl_init("http://www.myserver.com/Installer/components.zip");
    $fp fopen("components.zip""w");
    curl_setopt($chCURLOPT_FILE$fp);
    curl_setopt($chCURLOPT_HEADER0);
    curl_exec($ch);
    curl_close($ch);
    fclose($fp); 

  5. #5
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,099
    This is not possible with cURL, as you will need a client side script to update the percentage as the file is being downloaded.

    You can, however, display some statistics of the download once its finished. See curl_getinfo.
    In order to understand recursion, one must first understand recursion.
    If you feel like it, you can read my blog
    Signal > Noise

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •