Saturday, March 21

File's MIME type to validate using PHP.

<?php
    $valid_mime_types = array(
        "image/gif",
        "image/png",
        "image/jpeg",
        "image/pjpeg",
    );
    
    // Check that the uploaded file is actually an image
    // and move it to the right folder if is.
    if (in_array($_FILES["file"]["type"], $valid_mime_types)) {
        $destination = "uploads/" . $_FILES["file"]["name"];
        move_uploaded_file($_FILES["file"]["tmp_name"], $destination);
    }
?>

No comments:

Post a Comment