我是一名PHP新手,正在尝试使用以下方法向现有的PHP脚本添加进度条:
$ch=curl_init() or die("ERROR|<b>Error:</b> cURL Error");
curl_setopt($ch, CURLOPT_URL, $c);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_FILE, $fp);
//####################################################//
// This is required to curl give us some progress
// if this is not set to false the progress function never
// gets called
curl_setopt($ch, CURLOPT_NOPROGRESS, false);
// Set up the callback
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, 'callback');
// Big buffer less progress info/callbacks
// Small buffer more progress info/callbacks
curl_setopt($ch, CURLOPT_BUFFERSIZE, 128);
//####################################################//
curl_exec($ch);
curl_close($ch);
fclose($fp);
The callback function :
function callback($download_size, $downloaded, $upload_size, $uploaded)
{
$percent=$downloaded/$download_size;
// Do something with $percent
echo "$percent";
}
现在,我从PHP网站上复制粘贴了这个例子,但它不起作用??我的PHP版本是5.2.11,请建议可能出了什么问题?
编辑:我正在从另一个脚本中调用此php脚本。
信息:由于我的Web主机表示cPanel尚不支持5.3.x分支,因此我被困在5.2.X分支中,是否有任何解决方案?