如何在PHP中获取复制功能的进度状态?
发布时间:2020-12-13 18:22:47 所属栏目:PHP教程 来源:网络整理
导读:我需要知道如何在 PHP中获取copy()函数的状态. 我正在使用此功能下载远程文件,我想要一个该程序的进度条. 您需要编写自己的复制功能.首先通过HTTP HEAD请求检查文件大小,例如使用此解决方案: http://php.net/manual/en/function.filesize.php#92462 然后执
我需要知道如何在
PHP中获取copy()函数的状态.
我正在使用此功能下载远程文件,我想要一个该程序的进度条.
您需要编写自己的复制功能.首先通过HTTP HEAD请求检查文件大小,例如使用此解决方案:
http://php.net/manual/en/function.filesize.php#92462 然后执行此操作以获取文件: $remote = fopen('remote-file','r'); $local = fopen('local-file','w'); $read_bytes = 0; while(!feof($remote)) { $buffer = fread($remote,2048); fwrite($local,$buffer); $read_bytes += 2048; //Use $filesize as calculated earlier to get the progress percentage $progress = min(100,100 * $read_bytes / $filesize); //you'll need some way to send $progress to the browser. //maybe save it to a file and then let an Ajax call check it? } fclose($remote); fclose($local); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |