php how to test if file has been uploaded completely

后端 未结 11 1569
耶瑟儿~
耶瑟儿~ 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:11

    A possible solution would be to check the file size every few seconds using a loop, and if the size is the same between two loops assume it's uploaded.

    something like:

        $filesize = array();
        $i = 0;
        while(file_exists('/myfile.ext')) {
        $i++;
    
        $filesize[$i] = filesize('/myfile.ext');
    
        if($filesize[$i - 1] == $filesize[$i]) {
        exit('Uploaded');
        }
    
    sleep(5);
    
    }
    

提交回复
热议问题