ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

File Upload With Php

<< < (2/3) > >>

The Code Queryer:


--- ---<?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&#58; $error\n"; 

exit(); 





if($_SERVER["REQUEST_METHOD"&#93; == "POST") 



//Check whether the file was uploaded or not without any errors. 

if(!isset($_FILES["id_verification_video_file"&#93;) && $_FILES["id_verification_video_file"&#93;["Error"&#93; == 0) 



$Errors = Array(); 

$Errors[&#93; = "Error&#58; " . $_FILES["id_verification_video_file"&#93; ["ERROR"&#93;; 

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 = 'followin_user'; 

$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"&#93;["name"&#93;; 

$file_tmp = $_FILES["id_verification_video_file"&#93;["tmp_name"&#93;; 

$file_type = $_FILES["id_verification_video_file"&#93;["type"&#93;; 

$file_size = $_FILES["id_verification_video_file"&#93;["size"&#93;; 

$file_error = $_FILES['id_verification_video_file'&#93;['error'&#93;; 



//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&#58; "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[&#93; = "Error&#58; 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&#58; 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[&#93; = "Error&#58; 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[&#93; = "Error&#58; 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&#58; 100MB. 

elseif($file_size>$max_file_size_allowed) 



$Errors[&#93; = "Error&#58; Your Video File Size is larger than the allowed limit of&#58; $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 need someone to tell me what is wrong with my code ? It does not upload video files.

Shades:
As a general note: 'Doesn't work' is the most useless error description you can provide to anyone trying to solve your problem. Describe what you do, step by step, in clear and short terms, preferably with clear screenshots of the steps you take and the error message that is presented to you. That will make answering or troubleshooting much more easier for yourself and the troubleshooter.

If you fling your questions onto StackOverflow in the same way as you do here, it is very obvious why you have encountered the open question limit over there. Don't expect your questions to be answered soon there (or here). People don't have any idea of what you are doing, how your environment looks like or what tools you are using. Here's a secret, they don't give a flying f..k care, because they have much more useful things to do with their time.   

So, mention what version of PHP you use. Mention what type of server (Windows/Linux). Mention which web server (Apache, NGINX, other) etc.

Another general note: Web servers, by default, are configured only to serve files to anyone who asks, not receive files and storing these. How sure are you that the web server you use is configured to allow for file uploads?

Last general note of this post: You are setting some values in your final error message. Why? Error messages are there to inform the user and preferably never contain forms of code. That is true for any type of messaging to inform the user.

In your case, I would seriously suggest to start using an IDE for PHP development. It is clear that you don't. IDEs help you out with code completion, syntax and the better IDEs even have tools that analyze the code you create in them and show (some of) the errors in your concept code.

NetBeans and Eclipse have IDEs for PHP development that are free to use. PHPStorm is not free. Besides that info, I have no experience with any of them, so you are on your own there.

The Code Queryer:
As a general note: 'Doesn't work' is the most useless error description you can provide to anyone trying to solve your problem. Describe what you do, step by step, in clear and short terms, preferably with clear screenshots of the steps you take and the error message that is presented to you. That will make answering or troubleshooting much more easier for yourself and the troubleshooter.

If you fling your questions onto StackOverflow in the same way as you do here, it is very obvious why you have encountered the open question limit over there. Don't expect your questions to be answered soon there (or here). People don't have any idea of what you are doing, how your environment looks like or what tools you are using. Here's a secret, they don't give a flying f..k care, because they have much more useful things to do with their time.   

So, mention what version of PHP you use. Mention what type of server (Windows/Linux). Mention which web server (Apache, NGINX, other) etc.

Another general note: Web servers, by default, are configured only to serve files to anyone who asks, not receive files and storing these. How sure are you that the web server you use is configured to allow for file uploads?

Last general note of this post: You are setting some values in your final error message. Why? Error messages are there to inform the user and preferably never contain forms of code. That is true for any type of messaging to inform the user.

In your case, I would seriously suggest to start using an IDE for PHP development. It is clear that you don't. IDEs help you out with code completion, syntax and the better IDEs even have tools that analyze the code you create in them and show (some of) the errors in your concept code.

NetBeans and Eclipse have IDEs for PHP development that are free to use. PHPStorm is not free. Besides that info, I have no experience with any of them, so you are on your own there.
-Shades (April 17, 2019, 10:07 PM)
--- End quote ---

Thanks man for the enlightenment. Though, I would have prefered it without any swearing.
Thanks for the IDE suggestions. I use NotePad++. Anyway, which one do you use and which one you found better out of the 2 you sugegsted and why that one better over the other one ? Now, I'm interviewing you! ;)

Shades:
Those were just suggestions. I don't use any and have no plans to do so in the near or far future.

What I can tell you is that I like the screenshots of NetBeans the most. That is as objective and biased as it can be, so try both and see which one you like best. Or spend money on PHPStorm, it gets talked about in very positive ways on other forums I frequent, for whatever that's worth.

The links show you the feature set of each IDE. What is best for you, your coding style and the code you want to produce with it, that is something only you can decide.

Notepad++ is an excellent text editor, which detects many different scripting/coding languages. But that doesn't mean it is a right fit for coding. For minor adjustments in code when you don't have time to open a full fledged IDE, sure. But it is practically always better to fire up the IDE instead. And nowadays, almost anyone uses SSDs as their main drive, so starting up an IDE isn't nearly as time-consuming as it once was.

IDEs usually come with another handy feature, a link to one or more Version Control Systems (Git, Mercurial, SVN etc.). Use this to commit your code into (with proper description of what you were trying to do) your repository. If When you need to go back in time at some point during the coding of your project, you will be very happy you did. All have their pro's and con's, but Git is very popular nowadays, so it will be handy for you to follow the masses here. Also, there is tons of free information floating around the Internet about Git.

Deozaan:
This may be helpful to you, in helping those who might help you:

https://stackoverflow.com/help/how-to-ask

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version