-1
   clearstatcache();
    if($_FILES['images']){
        if ($_FILES['images']['error'] !== UPLOAD_ERR_OK) {
               $error[] = "Upload failed with error code " . $_FILES['images']['error'];                                
       }

        $info = getimagesize($_FILES['images']['tmp_name']);
        if ($info === FALSE) {
           $error[] = "Unable to determine image type of uploaded file";
        }

        if (($info[2] !== IMAGETYPE_GIF) && ($info[2] !== IMAGETYPE_JPEG) && ($info[2] !== IMAGETYPE_PNG)) {
                $error[] = "Not a gif/jpeg/png";
        }
        if ($_FILES["images"]["size"] > 100000) {//1mb limit
        $error[] = "Sorry, your file is too large.";
        }
}

this is my php code. checking if the file is empty. and i want. if the file is exist then php will check the file image. but if the user did not choose a image. the validation will just ignor it. i cant debug it. if im not picking an image the code still validation and error said Warning: getimagesize(): Filename cannot be empty in C:\xampp\htdocs\savings\LiveUpdate.php on line 10

Kenneth Suaverdez
  • 331
  • 1
  • 2
  • 9
  • edit your question to include the HTML form for this. You should also Google that error, there are many hits for it and could be because of many reasons. – Funk Forty Niner Nov 12 '16 at 15:19
  • Possible duplicate of [Warning: getimagesize() \[function.getimagesize\]: Filename cannot be empty warning message?](http://stackoverflow.com/questions/16043892/warning-getimagesize-function-getimagesize-filename-cannot-be-empty-warnin) – Funk Forty Niner Nov 12 '16 at 15:27
  • Possible duplicate of [Photo Upload getimagesize() warning - filename cannot be empty](http://stackoverflow.com/questions/17632353/photo-upload-getimagesize-warning-filename-cannot-be-empty) – Funk Forty Niner Nov 12 '16 at 15:27

1 Answers1

1

You didn't post your html, but the name images suggests you've a multi upload.

You should to specify the element of your array. Let me say [0]. See for more documentation: http://php.net/manual/en/features.file-upload.multiple.php

Change your code like so (see the added else, because if your upload fails, you only need to get the error!)

clearstatcache();

if(is_array($_FILES['images'])){
    if ($_FILES['images']['error'][0] !== UPLOAD_ERR_OK) {
       $error[] = "Upload failed with error code " . $_FILES['images']['error'][0];                                
    }
    else {
        $info = getimagesize($_FILES['images']['tmp_name'][0]);
        if ($info === FALSE) {
            $error[] = "Unable to determine image type of uploaded file";
        }

        if (($info[2] !== IMAGETYPE_GIF) && ($info[2] !== IMAGETYPE_JPEG) && ($info[2] !== IMAGETYPE_PNG)) {
            $error[] = "Not a gif/jpeg/png";
        }
        if ($_FILES["images"]["size"][0] > 100000) {//1mb limit
            $error[] = "Sorry, your file is too large.";
        }
    }
}
schellingerht
  • 5,726
  • 2
  • 28
  • 56
  • 1
    I fear the OP's been trying to upload files since their account creation on Stack. Have a look at all their questions http://stackoverflow.com/users/7148641/kenneth-suaverdez - I think you may be in for a very long haul. – Funk Forty Niner Nov 12 '16 at 15:18
  • its working. but i have still one problem. if i just submit(im not changing the file or opening any file) my code still check even i didn't choose a file and php error Warning: getimagesize(): Filename cannot be empty in C:\xampp\htdocs\savings\LiveUpdate.php on line 10 – Kenneth Suaverdez Nov 12 '16 at 15:19
  • I was editing my answer while you was commenting. See my edit. – schellingerht Nov 12 '16 at 15:20