dongqie5529 2015-01-20 16:30
浏览 44
已采纳

更正PHP中文件上载字段的变量引用

I am trying to successfully use the PHP empty() function. Currently my script references the input file field variable:

<input  class="fileUpload" name="flyer" type="file"  />

like this:

if (empty($_FILES['flyer']['name'])) {
//don't update the file 
}
else {
//update the file url
}

This currently updates the file URL to a value of null if it's empty. The problem could be something else but I think it's my variable reference. How can I correct this to get the empty function to work?

  • 写回答

2条回答 默认 最新

  • dtt78245 2015-01-20 16:33
    关注

    if it is a FILE type then you need to use the $_FILES[-name-]['error'] handler to check the quality of file, check http://php.net/manual/en/features.file-upload.errors.php

    Ignore the name value, what you want is

    if ($_FILES['flyer']['error'] == 4) {
    //// this file given was empty. 
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料