In my form I have 3 input fields for file upload:
<input type=file name="cover_image">
<input type=file name="image1">
<input type=file name="image2">
How can I check if cover_image
is empty – no file is put for upload?
You can check by using the size
field on the $_FILES
array like so:
if ($_FILES['cover_image']['size'] == 0 && $_FILES['cover_image']['error'] == 0)
{
// cover_image is empty (and not an error)
}
(I also check error
here because it may be 0
if something went wrong. I wouldn’t use name
for this check since that can be overridden)
Answer:
Method 1
if($_FILES['cover_image']['name'] == "") {
// No file was selected for upload, your (re)action goes here
}
Method 2
if($_FILES['cover_image']['size'] == 0) {
// No file was selected for upload, your (re)action goes here
}
Answer:
You can check if there is a value, and if the image is valid by doing the following:
if(empty($_FILES['cover_image']['tmp_name']) || !is_uploaded_file($_FILES['cover_image']['tmp_name']))
{
// Handle no image here...
}
Answer:
if (empty($_FILES['cover_image']['name']))
Answer:
simple :
if($_FILES['cover_image']['error'] > 0)
// cover_image is empty
Answer:
check after the form is posted the following
$_FILES["cover_image"]["size"]==0
Answer:
if( ($_POST) && (!empty($_POST['cover_image'])) ) //verifies if post exists and cover_image is not empty
{
//execute whatever code you want
}
Answer:
if($_FILES['img_name']['name']!=""){
echo "File Present";
}else{
echo "Empty file";
}
Answer:
if ($_FILES['cover_image']['size'] == 0 && $_FILES['cover_image']['error'] == 0)
{
// Code comes here
}
This thing works for me……..