Hi Guys.

I am having a problem using the $_FILES superglobal.

Everything (in my script) is working fine apart from one thing.

here is my script:

<?php
if(isset($_POST["submitform"])){
processform();
} else {
displayform();
}

function processform() {

if(isset($_FILES["filetosend"]) && $_FILES["filetosend"]["error"] == UPLOAD_ERR_OK) { 
if($_FILES["filetosend"]["type"] != "image/jpeg"){
echo "the file type must be a jpeg";
} elseif($_FILES["filetosend"]["size"] < 15000) {
echo "file cannot be any smaller than 15 kilobytes!";
} elseif($_FILES["filetosend"]["type"] == "video/mp4"){
echo "file must be an img";
}
}

}


function displayform(){
?>

<form method="post" action="practice.php" enctype="multipart/form-data">
<label for="filetosend"></label>
<input type="file" name="filetosend">
<input type="submit" name="submitform">
</form>
<?php
}
?>

Now, the problem I am having is in regards to the below code snippet:

} elseif($_FILES["filetosend"]["type"] == "video/mp4"){
echo "file must be an img";
}

.... The problem I am having is that when I try to upload a video and click the send button the error message: "file must be an img" does not display.

Obviously I made sure that the video (i tried to upload) was an mp4. But this code snippet just won't work.

Please help me guys.

Paul.

    Print the type and see what you get. Perhaps the server is identifying with a media type that isn't "video/mp4".

      Thanks laserlight.

      I am just practicing this stuff on my local host, not a web server.

      also, I checked that the video type was mp4 before I tried uploading the video file.

      and on top of that, I don't understand why the following code snippet wouldn't be enough on its own for when someone attempts to upload a video file?:

      if($_FILES["filetosend"]["type"] != "image/jpeg"){
      echo "the file type must be a jpeg";

      Paul.

        Write a Reply...