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";
}
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']
you can check if filesize($some_file) > 0