Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php如果为空,则跳过操作_Php_Mysql_File Upload_Is Empty - Fatal编程技术网

php如果为空,则跳过操作

php如果为空,则跳过操作,php,mysql,file-upload,is-empty,Php,Mysql,File Upload,Is Empty,我有一张带字段的表格 <input type="file" name="file" size="100" value=""> 用这个 if(!$_FILES['file']){ echo "file is empty" } 而不是 if(empty($_POST['file'])) 最后 if(!empty($_FILES['file'])){ //file has something } else{ //either

我有一张带字段的表格

<input type="file" name="file" size="100" value="">
用这个

if(!$_FILES['file']){ 
     echo "file is empty" 
}
而不是

if(empty($_POST['file']))

最后

    if(!empty($_FILES['file'])){ 
     //file has something
    }
   else{
     //either file is empty or filed is not set
   }

如果您想在文件为空时跳过上载图像,那么第一个If语句不应该是
If(!empty($\u POST[“file”])
?目前,如果$\u POST[“文件”]中没有任何内容,它将尝试运行第一段代码。好的,文件已上载,但
$sql
未运行,同时尝试更新其他字段并保留“文件”empty导致
无效的文件类型
被popI删除了我的问题中的大量代码,因为问题似乎是,无论填充的是表单文件还是起始
如果(!empty
语句未被遵循。您的答案是尝试重新构造
if else
语句。如果未填充文件字段,则更新sql日期的代码在哪里?
    if(!empty($_FILES['file'])){ 
     //file has something
    }
   else{
     //either file is empty or filed is not set
   }
  <?php
  if(!empty($_FILES))
  {
    $name = $_FILES["fileToUpload"]["name"];
    $type = $_FILES["fileToUpload"]["type"];
    $size = $_FILES["fileToUpload"]["size"];

    $match = mysql_query("SELECT * FROM `tb_name` WHERE file_name='$name'");
    if(!empty($match))
     {
       while($res=mysql_fetch_array($match))
       {
         if($type == "filetype")
           {
             //upload
           }
         else
            //error
       }
     }
    else
      //file already exists
  }
  ?>