1

Hi I am having an Undefined index: file error here it says $fileName, $fileTmpName, $fileSize, $fileError, $fleType are the problems.

if(isset($_POST['pic_submit'])) //if UPLOAD is clicked
    {
        $id = $_SESSION['user_id'];
        $fileName= $_FILES['file']['name'];
        $fileTmpName = $_FILES['file']['tmp_name'];
        $fileSize = $_FILES['file']['size'];
        $fileError = $_FILES['file']['error'];
        $fileType = $_FILES['file']['type'];

            var_dump($fileName);
        $fileExt = explode('.', $fileName);
        $target_dir = "/images/";
        $target_file = $target_dir.$fileName;


        $imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));

        $allowed = array('jpg', 'jpeg', 'png', 'pdf', 'gif');
        //if (in_array($fileActualExt, $allowed))
        //{

        if(isset($fileName))
        {
            $fileNameNew = uniqid('', true).".".$imageFileType;
            $fileDestination = '../images/'.$fileNameNew;
            move_uploaded_file($fileTmpName, $fileDestination);
        }

}

Miroslav Glamuzina
  • 4,472
  • 2
  • 19
  • 33

1 Answers1

1

Just ensure everything is set inside of your main if condition. The isset has an arity of variadic length, so you can ensure that all your conditions are set before you enter your loop.

Just doing:

if(isset($_POST['pic_submit'], $_FILES['file'])) //if UPLOAD is clicked

should cut it.

Miroslav Glamuzina
  • 4,472
  • 2
  • 19
  • 33