0

I'm setting up an application to accept a dynamic multipart files upload form.

I add a conditional if rule for uploaded type and extension. For conditional fulfilled to be accepted and store in DB, and for the empty post file should be ignored, for the rest should be got rejected.

        $allowedExts = array("gif", "jpeg", "jpg", "png", "pdf");
        $jumlah_syarat = count($_FILES);
        $forwardexts = array("");

        $diam = array();
        $tolak = array();
        foreach ($_FILES as $y => $file){
            $ext_file = strtolower(end(explode('.',$file['name'])));
            if (($file["type"] == "image/gif")
            || ($file["type"] == "image/jpeg")
            || ($file["type"] == "image/jpg")
            || ($file["type"] == "image/pjpeg")
            || ($file["type"] == "image/x-png")
            || ($file["type"] == "image/png")
            || ($file["type"] == "application/pdf")
            && in_array($ext_file, $allowedExts)) {
                $tmpfile = $file['tmp_name'];
                $namafile =  $noPendaf."-".$idPendaf."-".$y.".".$ext_file;
                $kefile = $path.$namafile;
                $syarats['idsyarat'][] = $y;
                $syarats['filesyarat'][$y] = $namafile;
                move_uploaded_file($tmpfile,$kefile);
            } elseif(($file["type"] == "") && in_array($ext_file, $forwardexts)){
                array_push($diam, 1);
            } else{
                array_push($tolak, 1);
            }
        }

For the expected result of the code above is to wait until all files uploaded and loop in foreach and then be filtered. But, I always get $tolak got array_push 1 before the file fully sent (uploaded) to the server

M.Hemant
  • 2,345
  • 1
  • 9
  • 14

1 Answers1

0

Add this code after your file uploaded to check its uploaded or not

$file_pointer = '';//here you need to pass your absolute path
if (file_exists($file_pointer)) {
    echo "The file $file_pointer exists";
}else {
    echo "The file $file_pointer does not exists";
}
M.Hemant
  • 2,345
  • 1
  • 9
  • 14