I am having a hard time using $_FILES
I want to check if file upload field is empty or not then apply a condition such that if file upload is empty then the script doesn't try uploading the file. How do I enforce this?
Given an HTML document containing input element and the task is to check whether an input element is empty or not with the help of JavaScript. Approach 1: Use element. files. length property to check file is selected or not.
We can clear the file input with JavaScript by setting the value property of the file input to an empty string or null .
PHP empty() Function The empty() function checks whether a variable is empty or not. This function returns false if the variable exists and is not empty, otherwise it returns true. The following values evaluates to empty: 0.
if($_FILES["file"]["error"] != 0) { //stands for any kind of errors happen during the uploading }
also there is
if($_FILES["file"]["error"] == 4) { //means there is no file uploaded }
This should work
if ( ! empty($_FILES)) {...}
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