Php Folks,
Why do I keep getting this error and how to solve it ?
Notice: Undefined index: video_verification_file in C:\xampp\htdocs\test\upload.php on line 33
Trying to build a web form where you submit your img file. You should get error if the file is not img file. I tried uploading .php file to see if I get the default error alert or not but ain;t getting it.
Default error:
Error: Please select a valid file format.
Why do I keep getting this error and how to solve it ?
Notice: Undefined index: video_verification_file in C:\xampp\htdocs\test\upload.php on line 33
Trying to build a web form where you submit your img file. You should get error if the file is not img file. I tried uploading .php file to see if I get the default error alert or not but ain;t getting it.
Default error:
Error: Please select a valid file format.
PHP:
<?php
// Check if the form was submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){
// Check if file was uploaded without errors
if(isset($_FILES["video_verification_file"]) && $_FILES["video_verification_file"]["error"] == 0){
$allowed = array("jpg" => "image/jpg", "jpeg" => "image/jpeg", "gif" => "image/gif", "png" => "image/png");
$filename = $_FILES["video_verification_file"]["name"];
$filetype = $_FILES["video_verification_file"]["type"];
$filesize = $_FILES["video_verification_file"]["size"];
// Verify file extension
$ext = pathinfo($filename, PATHINFO_EXTENSION);
if(!array_key_exists($ext, $allowed)) die("Error: Please select a valid file format.");
// Verify file size - 5MB maximum
$maxsize = 5 * 1024 * 1024;
if($filesize > $maxsize) die("Error: File size is larger than the allowed limit.");
// Verify MYME type of the file
if(in_array($filetype, $allowed)){
// Check whether file exists before uploading it
if(file_exists("upload/" . $_FILES["video_verification_file"]["name"])){
echo $_FILES["video_verification_file"]["name"] . " is already exists.";
} else{
move_uploaded_file($_FILES["video_verification_file"]["tmp_name"], "upload/" . $_FILES["video_verification_file"]["name"]);
echo "Your file was uploaded successfully.";
}
} else{
echo "Error: There was a problem uploading your file. Please try again.";
}
} else{
echo "Error: " . $_FILES["video_verification_file"]["error"];
}
}
?>
<form method="post" action="">
<fieldset>
<p align="left"><h3><?php $site_name ?> Video Verification Form</h3></p>
<div class="form-group">
<p align="left"><label>Video File:</label>
<input type="file" name="video_verification_file" id="video_verification_file" value ="Upload Image"></p>
</div>
</fieldset>
<p align="left"><button type="video_verification_submit" class="btn btn-default" name="video_verification_submit">Submit!</button></p>
</form>
</body>
</html>