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 like to check if file has been uploaded or if user is still uploading. It is essential because then I know if I can work with that file or wait until it is uploaded. Thank you.
php define ('MAX_FILE_SIZE', 1000000); $permitted = array('image/gif', 'image/jpeg', 'image/png', 'image/pjpeg', 'text/plain'); if ($_FILES['file']['type'] == $permitted && $_FILES['file']['size'] > 0 && $_FILES['file']['size'] <= MAX_FILE_SIZE) { move_uploaded_file($_FILES, $uploadedfile); echo ('<img src="'.
length property in jQuery to check the file is selected or not. If element. files. length property returns 0 then the file is not selected otherwise file is selected.
php stores all temporary files, that includes uploaded files, in the temporary files directory as specified in the php. ini. Note that for uploads, those files might be removed as soon as the script the file was uploaded to was terminated (so unless you delay that script, you probably won't see the uploaded file).
If you have control over the application doing the upload, you can require that it upload the file to name.tmp
, and when it's done uploading rename it to name.final
. Your PHP script could look only for *.final
names.
I had the same scenario and found a quick solution that worked for me:
While a file is uploading via FTP, the value of filemtime($yourfile)
is continuously modified. When time() minus filemtime($yourfile)
is more than X
, uploading has stopped. In my scenario, 30 was a good value for x, you might want to use any diferent value, but it should usefully be at least 3.
I do know that this method doesn’t guarantee the file’s integrity, but, as no one but me is going to upload, i dare to assume that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With