/    Sign up×
Community /Pin to ProfileBookmark

Why Uploading Fails ?

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.
?>
[/code]

I get echoed: “has failed to upload via HTTP POST!”.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 12.2019 — This looks funky to me, since if $_FILES["id_verification_video_file"] is not set, then the next test should be throwing an error, since $_FILES["id_verification_video_file"]["Error"] won't be set, either.
<i>
</i>if(!isset($_FILES["id_verification_video_file"]) &amp;&amp; $_FILES["id_verification_video_file"]["Error"] == 0)

Probably could be something like:
<i>
</i>f(!isset($_FILES["id_verification_video_file"]) {
// handle error of nothing being uploaded with the expected name
}
elseif(!empty($_FILES["id_verification_video_file"]["Error"])) {
// handle case where some error occurred
}
else {
// continue processing the upload
}
Copy linkTweet thisAlerts:
@site-developerauthorApr 17.2019 — NogDog Pal,

I'd rather you suggest me what errors I should go for:
<i>
</i>if(!isset($_FILES["id_verification_video_file"]) {
// handle error of nothing being uploaded with the expected name
}
elseif(!empty($_FILES["id_verification_video_file"]["Error"])) {
// handle case where some error occurred
}
else {
// continue processing the upload
}


My best shot ...
<i>
</i>if($_SERVER["REQUEST_METHOD"] == "POST")
{
//Check whether the file was uploaded or not without any errors.
if(!isset($_FILES["id_verification_video_file"])) die("Upload your video file");
elseif($_FILES["id_verification_video_file"]["Error"] == 0)
{
$Errors = Array();
$Errors[] = "Error: " . $_FILES["id_verification_video_file"] ["ERROR"];
print_r($_FILES); ?&gt;&lt;br&gt;&lt;?php
print_r($_ERRORS);
exit();
}

I was given this error code by another. Not sure if it is correct. Note the CAPITALS and non-capitals. Not seeming correct to me.
<i>
</i>$Errors = Array();
$Errors[] = "Error: " . $_FILES["id_verification_video_file"] ["ERROR"];
print_r($_FILES); ?&gt;&lt;br&gt;&lt;?php
print_r($_ERRORS);
exit();

I get this error ?

Notice: Undefined index: Error in C:xampphtdocstestupload.php on line 20

Notice: Undefined index: ERROR in C:xampphtdocstestupload.php on line 23

Array ( [id_verification_video_file] => Array ( [name] => id_check.mp4 [type] => [tmp_name] => [error] => 1 [size] => 0 ) )

Notice: Undefined variable: _ERRORS in C:xampphtdocstestupload.php on line 25
×

Success!

Help @site-developer spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...