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条)

报告相同问题?