douhui9631 2019-04-05 20:20
浏览 198
已采纳

如何知道文件是否为空

I had a problem. My condition always returns "All fields must be completed". What should I do? Thank you for your help ...

if (! empty ($ _ FILES ['myFile'] ['name'])) {


    $ fileImage = $ _FILES ['myFile'] ['name'];
    $ extension = pathinfo ($ fileImage, PATHINFO_EXTENSION);
    $ tmp_name = $ _FILES ["myFile"] ["tmp_name"];

    if ((exif_imagetype ($ tmp_name) == 2) || (exif_imagetype ($ tmp_name) == 3)) {
          $ userAvatar = $ _SESSION ['id']. '.' . $ Extension;
          $ uploadDestination = "img / avatars /". $ Useravatar;
          $ insertAvatar = $ db-> prepare ("UPDATE member SET avatar =? WHERE id =?");
          $ insertAvatar-> execute (array ($ userAvatar, $ _SESSION ['id']));
          move_uploaded_file ($ tmp_name, $ uploadDestination);
          header ( 'Location: profil.php? id =' $ _ SESSION [ 'id'].)

    } else {
        $ error = 'This format is not taken into account!';
    }

} else {
    $ error = "All fields must be completed";
}
  • 写回答

2条回答 默认 最新

  • duanji2002 2019-04-05 20:32
    关注

    The $_FILES always have

     [file] => Array
        (
            [name] => MyFile.jpg
            [type] => image/jpeg
            [tmp_name] => /tmp/php/php6hst32
            [error] => UPLOAD_ERR_OK
            [size] => 98174
        )
    

    You can use the following to get the size

    $_FILES['file']['size']
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?