curl-and-php
Uploading Progress using libcurl
Date: Sun, 18 Dec 2005 05:55:47 +0200
There is some code to upload file via POST to destination place. I'ts
writen for command line. To be able to view current uploading status I
made:
<?php curl_setopt($ch,CURLOPT_NOPROGRESS,false); ?>
everything works fine!
Now there is another problem. Files are very big, therefore I run my
script in background. To be able to control uploading status and have
some logs I write all script actions to database. In field "status" I
write "uploading...", and when script finished "status" is changed on
"done". So, I'd like to add to my table new field, that will contain
size of already uploaded data(or percentage, never mind).
According to documrntation, next option may be used to do it:
<?php curl_setopt($ch,CURLOPT_PROGRESSFUNCTION,'progress'); ?>
where "progress" - callback-function name.
In following code part after starting displayed standart progress-bar
(as if callback-function not called, just CURLOPT_NOPROGRESS switched
to FALSE)
echo "Uploading file...\n";$this->log.="Uploading file...\n";
$postData = array();
$postData['filecontent'] ='@'.$file;
$postData['submit'] = "Upload! (No SSL)";
$postData['login'] = $this->login;
$postData['password'] = $this->password;
function progress($clientp,$dltotal,$dlnow,$ultotal,$ulnow){
echo "$clientp, $dltotal, $dlnow, $ultotal, $ulnow";
return(0);
}
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$this->uploadlink);
curl_setopt($ch, CURLOPT_TIMEOUT,$this->timeout);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_NOPROGRESS,false);
curl_setopt($ch,CURLOPT_PROGRESSFUNCTION,'progress');
curl_setopt($ch,CURLOPT_POSTFIELDS,$postData);
$result = curl_exec($ch);
Please, help...
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2005-12-18