Php Seniors,
Why is this line malfunctioning ?
if(!array_key_exists($file_extension, $allowed_file_extensions)) die("Error: Select a valid video file format. Select an Mp4 file.");
I allowed the file type "mp4" and then fed the script (trying to uploade an mp4 file) an mp4 file.
I should get mssg upload successful and only get echoed errors if the selected file is not a video file. Since, I selected a video file to upload via the html form then I should not get any errors echoed. Common sense!
But guess what ? I get error message echoed: "Select a valid video file format. Select an Mp4 file."
Why is that ?
Here my code:
$file_name = $_FILES["id_verification_video_file"]["name"];
$file_tmp = $_FILES["id_verification_video_file"]["tmp_name"];
$file_type = $_FILES["id_verification_video_file"]["type"];
$file_size = $_FILES["id_verification_video_file"]["size"];
$file_error = $_FILES['id_verification_video_file']['error'];
$file_extension = pathinfo($file_name, PATHINFO_EXTENSION);
if(file_exists("$directory_path . $user/ . $file_name"))
{
$Errors[] = "Error: You have already uploaded a video file to verify your ID!";
exit();
}
else
{
//Feed allowed File Extensions List.
$allowed_file_extensions = array('mp4');
//Feed allowed File Size.
$max_file_size_allowed_in_bytes = 1024*1024*1; //Allowed limit: 100MB.
$max_file_size_allowed_in_kilobytes = 1024*1;
$max_file_size_allowed_in_megabytes = 1;
$max_file_size_allowed = "$max_file_size_allowed_in_bytes";
//Create a fileinfo resource.
$finfo = finfo_open(FILEINFO_MIME_TYPE);
//Apply the FileInfo resource and the finfo_file() function to a given file.
$mime = finfo_file($finfo,$file_name);
//Close the fileinfo resource.
finfo_close($finfo);
//Verify File Extension.
if(!array_key_exists($file_extension, $allowed_file_extensions)) die("Error: Select a valid video file format. Select an Mp4 file.");
The following code fails to move the FILE to it's intended place:
//Move uploaded File to newly created directory on the server.
move_uploaded_file($file_tmp, $directory_path . "$user/" . $file_name); //IS THIS LINE CORRECT ?
//Notify user their Id Verification Video File was uploaded successfully.
echo "Your Video File \"$file_name\" has been uploaded successfully!";
exit();
Before, attempted this with no luck too:
//Move uploaded File to newly created directory on the server.
move_uploaded_file("$file_tmp", "$directory_path . $user/ " . "$file_name"); //IS THIS LINE CORRECT ?
//Notify user their Id Verification Video File was uploaded successfully.
echo "Your Video File \"$file_name\" has been uploaded successfully!";
exit();