В моей форме у меня есть 3 поля ввода для загрузки файла:
<input type=file name="cover_image">
<input type=file name="image1">
<input type=file name="image2">
Как проверить, пуст ли cover_image
- файл не загружен для загрузки?
В моей форме у меня есть 3 поля ввода для загрузки файла:
<input type=file name="cover_image">
<input type=file name="image1">
<input type=file name="image2">
Как проверить, пуст ли cover_image
- файл не загружен для загрузки?
Вы можете проверить, используя поле size
в массиве $_FILES
:
if ($_FILES['cover_image']['size'] == 0 && $_FILES['cover_image']['error'] == 0)
{
// cover_image is empty (and not an error)
}
(я также проверяю error
здесь, потому что это может быть 0
, если что-то пошло не так. Я бы не использовал name
для этой проверки, так как это можно переопределить)
Метод 1
if($_FILES['cover_image']['name'] == "") {
// No file was selected for upload, your (re)action goes here
}
Метод 2
if($_FILES['cover_image']['size'] == 0) {
// No file was selected for upload, your (re)action goes here
}
if (empty($_FILES['cover_image']['name']))
Вы можете проверить, есть ли значение, и если изображение действительно, выполнив следующие действия:
if(empty($_FILES['cover_image']['tmp_name']) || !is_uploaded_file($_FILES['cover_image']['tmp_name']))
{
// Handle no image here...
}
if( ($_POST) && (!empty($_POST['cover_image'])) ) //verifies if post exists and cover_image is not empty
{
//execute whatever code you want
}
проверить после публикации формы
$_FILES["cover_image"]["size"]==0
просто:
if($_FILES['cover_image']['error'] > 0)
// cover_image is empty
if($_FILES['img_name']['name']!=""){
echo "File Present";
}else{
echo "Empty file";
}
if ($_FILES['cover_image']['size'] == 0 && $_FILES['cover_image']['error'] == 0)
{
// Code comes here
}
Эта вещь работает для меня........