我们如何在codeigniter中同时上传多个文件时检查文件是否为空?
<input type="file" name = "user_file[]" multiple />
<input type="file" name = "user_file[]" multiple />
控制器代码:
if (empty($_FILES['user_file']['name'])) {
echo'<script>alert("please upload a file or write something")</script>';
exit();
}
但它不起作用,空文件也上传??请有人为此提供解决方案......
答案 0 :(得分:1)
您可以使用
if (filesize($file_path) == 0){
echo "The file is empty";
}
或尝试
if (trim(file_get_contents($file_path)) == false) {
echo "The file is empty";
}
答案 1 :(得分:0)
试试这个
if ($_FILES["fileToUpload"]["size"] == 0) {
echo "Sorry, your file is empty.";
}