Reputation: 67
I have the following on a PHP processing file.
if(isset($_FILES['cv'])){
// run function here
}
Only problem is that the function is getting all the time ... Shouldnt it only be run if a file has been input?
Upvotes: 2
Views: 256
Reputation: 5379
If you are checking if a file is correctly uploaded, you should check:
$_FILES['cv']['error'] == UPLOAD_ERR_OK
Upvotes: 1
Reputation: 342635
The 'cv' key will always be set when a form element of the same name is present. You could test for an empty file instead. Here's one way:
if(isset($_FILES['cv']) && $_FILES['cv']['size'] > 0){
// run function here
}
Upvotes: 3
Reputation: 19719
I think that the browser sends an empty field when the user hasn't selected a file, yet it does send it so it is set.
if(isset($_FILES['cv']) && $_FILES['cv']!=null && $_FILES['cv']!=""){
//Execute
}
Upvotes: 0