在PHP中检测文件是完整还是部分 [英] Detecting whether a file is complete or partial in PHP

查看:177
本文介绍了在PHP中检测文件是完整还是部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此系统中,SFTP将用于将大型视频文件上传到服务器上的特定目录。我写一个PHP脚本,将用于将完全上传的文件复制到另一个目录。

In this system, SFTP will be used to upload large video files to a specific directory on the server. I am writing a PHP script that will be used to copy completely uploaded files to another directory.

我的问题是,什么是一个好的方法来判断一个文件是否完全上传?我考虑记录文件大小,休眠几秒钟的脚本,再次读取大小,并比较两个数字。

My question is, what is a good way to tell if a file is completely uploaded or not? I considered taking note of the file size, sleeping the script for a few seconds, reading the size again, and comparing the two numbers. But this seems very kludgy.

推荐答案

在理论上,如果你允许从PHP运行系统命令,你可以尝试得到您的sftp服务器的pid使用 pidof 命令进行处理,然后使用 lsof 输出检查当前检查的上传文件是否存在打开的文件描述符。

In theory, in case you are allowed to run system commands from PHP you can try to get the pids of your sftp server processes with pidof command and then use lsof output to check if open file descriptors exist for the currently checked upload file.

这篇关于在PHP中检测文件是完整还是部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆