php how to test if file has been uploaded completely

后端 未结 11 1541
耶瑟儿~
耶瑟儿~ 2021-02-01 15:24

Is there any way to check if file has been uploaded completely on the server? My scenario: User uploads file over ftp and my other PHP task is running in cronjob. Now I would li

11条回答
  •  南方客
    南方客 (楼主)
    2021-02-01 16:17

    if you are running php on linux then lsof can help you

    $output = array();
    exec("lsof | grep file/path/and/name.ext",$output);
    if (count($output)) {
      echo 'file in use';
    } else {
      echo 'file is ready';
    }
    

    EDIT: in case of permission issue. by using sudo or suid methods php script can get required permissions to execute lsof command. to set suid you have to issue following command as root.

    su root
    chmod u+s /usr/sbin/lsof
    

提交回复
热议问题