【问题标题】:codeigniter upload files checking if emptycodeigniter 上传文件检查是否为空
【发布时间】:2017-04-20 08:27:16
【问题描述】:

我想检查文件上传是否为空,但它只是一种方式.. 总是空的。这就是我所拥有的。

if(isset($_FILES) && @$_FILES['file_upload']['error'] != '4'){
    //Upload file then insert ticket info to database
}else{
    //Just insert info to database
}

无论文件字段是否为空,它总是转到 if 语句。

【问题讨论】:

  • 也许这会对你有所帮助:stackoverflow.com/questions/43417033/…
  • 谢谢,我正在调查中
  • 我猜你的输入类型文件属性名不匹配。
  • @teshvenk 这是我的输入类型名称
  • @TheTruth 因为它是多文件上传,你必须使用像 $_FILES['file_upload']['error'][0]

标签: php codeigniter file-upload


【解决方案1】:

应该是:

if ($_FILES['file_upload']['error'] !== 4){
  //Upload file then insert ticket info to database
} else {
    //Just insert info to database
}

简单的方法是(推荐):

if (empty($_FILES['userfile']['name'])) { 
   //Upload file then insert ticket info to database
} else {
    //Just insert info to database
}

【讨论】:

  • 不,不是 :( 很遗憾
  • 尝试:var_dump(empty($_FILES['userfile']['name']) 并在您的问题中发布错误。
  • 它不返回任何东西
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-31
  • 1970-01-01
  • 2012-12-06
  • 2021-12-25
  • 2012-05-25
相关资源
最近更新 更多