PHP CURL Progress - Will pay today it self

Discussion in 'PHP' started by bloodsavi, Nov 3, 2008.

  1. #1
    I need to upload files to a remote server from my local computer using a PHP script. So far everything is working nicely. The only problem is, how do I get a progress of the bytes sent so far. For example the percentage of the upload. Because sometimes I will have to upload large files, So its necessary for me to get the progress of the uploads.

    This is what I have so far, and It works properly. I only need to know how to get the progress of my uploads -

    
            $wwwhandle = curl_init();
            curl_setopt($wwwhandle, CURLOPT_URL, $url);
            curl_setopt($wwwhandle, CURLOPT_HEADER, 0); 
            curl_setopt($wwwhandle, CURLOPT_RETURNTRANSFER,1); 
            curl_setopt($wwwhandle, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); 
            curl_setopt($wwwhandle, CURLOPT_COOKIEJAR, $file);
            curl_setopt($wwwhandle, CURLOPT_COOKIEFILE, $file);
            if ($action == "POST") {
                curl_setopt($wwwhandle, CURLOPT_POST, 1);
                curl_setopt($wwwhandle, CURLOPT_POSTFIELDS, $parameter); 
            }
            if ($action == "GET" && $parameter != "") $url .= "?" . $parameter;
            $result=curl_exec($wwwhandle);
            curl_close($wwwhandle);
            return $result;
    
    PHP:
    Thanks.
     
    bloodsavi, Nov 3, 2008 IP
  2. FredL

    FredL Peon

    Messages:
    14
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    FredL, Nov 4, 2008 IP
  3. bloodsavi

    bloodsavi Peon

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    FredL Thanks a lot for the reply. But the problem here is that when I execute the line - curl_exec($wwwhandle); It will not give me any status of the upload. So its not possible for me to create a progress bar. I need a method to get the status from CURL. There is a function called CURLOPT_READFUNCTION to get the status, but still its not supported by PHP/CURL. It works fine when I use the command line CURL.Hope someone can help me out here.

    Thanks.
     
    bloodsavi, Nov 4, 2008 IP
  4. maestria

    maestria Well-Known Member

    Messages:
    705
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #4
    Hi,

    Have you received the script for this?
    if not, i have it with me.
    Please let me know in case you are yet to complete this task.
     
    maestria, Nov 4, 2008 IP