0

I have this section of PHP for a pdf file upload. My echo statement is returning image/png when I upload a png file, and application/pdf when I upload a pdf, but neither file will upload, and I still receive the "Not the allowed file type" alert from the switch's default case. Any ideas?

$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$uploadOk = 1;

// Check if upload is correct file type
if(isset($_POST["submit"])) {
    $mime = finfo_file($finfo, $_FILES["fileToUpload"]["tmp_name"]);
    echo "$mime";
    switch ($mime) {
        case 'image/png': //Type allowments
        case 'application/pdf':
        case 'pdf':
            $uploadOk = 1;
        default:
            echo "<script type='text/javascript'>alert('Not the allowed file type');</script>"; //Messy JS alert message
            $uploadOk = 0;
    }
}
Ivar
  • 6,138
  • 12
  • 49
  • 61
rborum
  • 124
  • 1
  • 11

0 Answers0