0

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";
}
ugexe
  • 5,297
  • 1
  • 28
  • 49
  • 3
    `empty()` is for PHP variables. `filesize()` returns the size of a file in bytes. – Honk der Hase Apr 05 '19 at 20:23
  • Possible duplicate of [Best way to determine if a file is empty (php)?](https://stackoverflow.com/questions/4857182/best-way-to-determine-if-a-file-is-empty-php) – SuperKogito Apr 05 '19 at 22:21

2 Answers2

0

you can check if filesize($some_file) > 0

jtylerm
  • 482
  • 4
  • 15
0

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']
Rakesh Jakhar
  • 6,380
  • 2
  • 11
  • 20