pavlosgr Posted July 26, 2012 Share Posted July 26, 2012 Hello I'm uploading a file and I want to detect when the uploaded file size is greater than the upload_max_filesize parameter of my server. I tried to check the $_FILES['file']['size'] but I saw that it is filled with 0 when the uploaded file size is greater than the above parameter. Is there any way to detect the uploaded file size in the above case? I'm not really very keen on posting file size from the html form. Thanks very much Quote Link to comment https://forums.phpfreaks.com/topic/266271-file-upload-file-size-0/ Share on other sites More sharing options...
memfiss Posted July 26, 2012 Share Posted July 26, 2012 have u added enctype in ur form ? <FORM enctype="multipart/form-data" method="post"> Quote Link to comment https://forums.phpfreaks.com/topic/266271-file-upload-file-size-0/#findComment-1364551 Share on other sites More sharing options...
pavlosgr Posted July 26, 2012 Author Share Posted July 26, 2012 Yes I have <form action="upload_file.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/266271-file-upload-file-size-0/#findComment-1364553 Share on other sites More sharing options...
Pikachu2000 Posted July 26, 2012 Share Posted July 26, 2012 http://www.php.net/manual/en/features.file-upload.errors.php Quote Link to comment https://forums.phpfreaks.com/topic/266271-file-upload-file-size-0/#findComment-1364557 Share on other sites More sharing options...
PFMaBiSmAd Posted July 26, 2012 Share Posted July 26, 2012 You need to test the ['error'] element - http://us2.php.net/manual/en/features.file-upload.errors.php If($_FILES['file']['error'] === 0){ // test for exactly === a zero value // the file uploaded successfully and you can access the ['name'], ['type'], ['size'], and ['tmp_name'] elements } Quote Link to comment https://forums.phpfreaks.com/topic/266271-file-upload-file-size-0/#findComment-1364559 Share on other sites More sharing options...
pavlosgr Posted July 26, 2012 Author Share Posted July 26, 2012 You need to test the ['error'] element - http://us2.php.net/manual/en/features.file-upload.errors.php I am testing the ['error'] element and was getting an error code. What I was looking for and didn't clear out in my question was how I'm sure that the code that I'm peeking means file size exceeds server max file size. http://www.php.net/manual/en/features.file-upload.errors.php But I had missed the above page which relates error code 1 with the error I was looking for. Thank you all for your help Quote Link to comment https://forums.phpfreaks.com/topic/266271-file-upload-file-size-0/#findComment-1364597 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.