How to Upload PHP Video Files

By Tiesha Whatley

PHP gives the Web developer the power to create websites that interact with and are updated by users. Users can post text, images, videos and any other content on websites that are coded with PHP. To provide the option to upload videos with PHP on your website, create a form that works as the user interface and the PHP code that will work in the back end to handle and successfully upload the video file.

Step 1

Open a blank page in a text editor, such as Notepad, or a Web-authoring application like Dreamweaver. If you use Dreamweaver or another WYSIWYG (what you see is what you get) type application, make sure to change the view to HTML.

Step 2

Type in the code for the form that will be used as the user interface for uploading the video files. The HTML code for the form should look like this:"

Video Upload FormUse this form to upload your video files.
Video file directory path:
"This is just a basic form that calls on the PHP file "uploadvideofile.php" to handle the file you selected to upload. Save this document and open another blank document.

Step 3

Type in the PHP code to handle the video upload. The challenge with uploading videos is the file size. You will need the PHP code to be able to handle large video files. The code should look like this:"Unknown extension!';$errors=1;}else{//get the size of the video$size=filesize($_FILES['video']['tmp_name']);//compare the size with the maxim size we defined and print error if biggerif ($size > MAX_SIZE*1024){echo '

You have exceeded the size limit!

';$errors=1;}//give the video a unique name in case a video already exists with the name on the server$video_name=time().'.'.$extension;//assign a folder to save the video to on your server$newname="video/".$video_name;//verify that the video has been loaded$copied = copy($_FILES['video']['tmp_name'], $newname);if (!$copied) {echo '

Copy unsuccessful!

';$errors=1;}}}}//If no errors registered, print the success messageif(isset($_POST['Submit']) && !$errors) {echo "

File Uploaded Successfully! Try again!

";}?>"Leave out the quotation marks on the first and last line. Save the file as "uploadvideofile.php" so that the form above uses this file to handle the uploading of the video. Upload both files to your Web server.