Php Budiies,
Why my script fails to upload ?
I’d appreciate it if you checkout my code and answer my questions you saee in my coding comments (CAPITAL LETTERS).
Thanks
[code]
<?php
//Required PHP Files.
include ‘header_account.php’; //Required on all webpages of the Site.
?>
<?php
if (!$conn)
{
$error = mysqli_connect_error();
$errno = mysqli_connect_errno();
print “$errno: $errorn”;
exit();
}
if($_SERVER[“REQUEST_METHOD”] == “POST”)
{
//Check whether the file was uploaded or not without any errors.
if(!isset($_FILES[“id_verification_video_file”]) && $_FILES[“id_verification_video_file”][“Error”] == 0)
{
$Errors = Array();
$Errors[] = “Error: ” . $_FILES[“id_verification_video_file”] [“ERROR”];
print_r($_FILES); ?><br><?php
print_r($_ERRORS);
exit();
}
else
{
//Feed Id Verification Video File Upload Directory path.
$directory_path = ‘uploads/videos/id_verifications/’;
//Make Directory under $user in ‘uploads/videos/id_verifications’ Folder.
$directory_path_and_user_dir = “uploads/videos/id_verifications/$user”;
if(!is_dir($directory_path_and_user_dir)) //IS THIS LINE CORRECT ?
{
$db_user = ‘root’;
$mode = 0755;
mkdir($directory_path_and_user_dir, $mode, TRUE); //IS THIS LINE CORRECT ?
}
//Grab Uploading File details.
$Errors = Array(); //SHOULD I KEEP THIS LINE OR NOT ?
$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’];
//Grab Uploading File Extension details.
$file_extension = pathinfo($file_name, PATHINFO_EXTENSION);
$directory_path_and_user_dir_and_user_file = “$directory_path_and_user_dir/$file_name”;
//if(file_exists(“$directory_path_and_user_dir_and_user_file”)) //THIS LINE IS NOT GIVING THE ERROR THAT FILE HAS ALREADY BEEN UPLOADED. INSTEAD GIVES THE ECHO THAT IS 26 LINES BELOW HERE: “Your Video File “$file_name” has been uploaded successfully!”
if(file_exists($directory_path_and_user_dir_and_user_file)) ////THIS LINE IS NOT GIVING THE ERROR THAT FILE HAS ALREADY BEEN UPLOADED. INSTEAD SHOWING BLANK WHITE PAGE.
{
$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” => “video/mp4”);
//Feed allowed File Size.
$max_file_size_allowed_in_bytes = 1024*1024*100; //Allowed limit: 100MB.
$max_file_size_allowed_in_kilobytes = 1024*100;
$max_file_size_allowed_in_megabytes = 100;
$max_file_size_allowed = “$max_file_size_allowed_in_bytes”;
//Verify File Extension.
if(!array_key_exists($file_extension, $allowed_file_extensions))
{
$Errors[] = “Error: Select a valid video file format. Select an Mp4 file.”;
}
//Verify MIME Type of the File.
elseif(!in_array($file_type, $allowed_file_extensions))
{
$Errors[] = “Error: There was a problem uploading your file $file_name! Make sure your file is an MP4 video file. You may try again.”; //IS THIS LINE CORRECT ?
}
//Verify File Size. Allowed Max Limit: 100MB.
elseif($file_size>$max_file_size_allowed)
{
$Errors[] = “Error: Your Video File Size is larger than the allowed limit of: $max_file_size_allowed_in_megabytes.”;
}
if(!is_uploaded_file($file_tmp)) //SHOULD I CHECK WITH $file_name OR $file_tmp ?
//if(!is_uploaded_file($file_name)) //SHOULD I CHECK WITH $file_name OR $file_tmp ?
{
die(“$file_tmp has failed to upload via HTTP POST!”);
//die(“$file_name has failed to upload via HTTP POST!”);
}
else
{
echo “$file_tmp has been successfully uploaded via HTTP POST!”;
//echo “$file_name has been successfully uploaded via HTTP POST!”;
}
//Move uploaded File to newly created directory on the server.
if(!move_uploaded_file($file_tmp, “$directory_path_and_user_dir/$file_name”)) //SHOULD I CHECK WITH $file_name OR $file_tmp ?
//if(!move_uploaded_file($file_name, “$directory_path_and_user_dir/$file_name”)) //SHOULD I CHECK WITH $file_name OR $file_tmp ?
{
$db_user = ‘root’; //IS THIS LINE NECESSARY ?
$mode = 0755; //IS THIS LINE NECESSARY ?
//Notify user their Id Verification Video File uploading failed.
echo “Your Video File “$file_name” has failed to be uploaded! You may try some other time.”;
exit();
}
else
{
echo “Your Video File “$file_name” has been uploaded successfully!”;
exit();
}
}
}
}
?>
<form METHOD=”POST” ACTION=”” enctype=”multipart/form-data”>
<fieldset>
<p align=”left”><h3><?php $site_name ?> ID Video Verification Form</h3></p>
<div class=”form-group”>
<p align=”left”<label>Video File: </label>
<input type=”file” name=”id_verification_video_file” id=”id_verification_video_file” value=”uploaded ‘Id Verification Video File.'”></p>
</div>
</fieldset>
<p align=”left”><button type=”submit” class=”btn btn-default” name=”id_verification_video_file_submit”>Submit!</button></p>
</form>
</body>
</html>
<?php
include ‘footer_account.php’; //Required on all webpages of the Site.
?>
I get echoed: “has failed to upload via HTTP POST!”.