PHP Video File Upload in Server
Configure The “php.ini” File in local server or Linux ,Centos.for
In your “php.ini” file, search for the file_uploads directive, and set it to On:
For centos or linux you need to configure the these changes in server. /etc/php.ini
upload_max_filesize = 2M
file_uploads = On
change the upload_max_filesize = userdefine size
;upload_tmp_dir =
uncomment the variable and change the default tmp directory
upload_tmp_dir = ‘/var/www/html/tmp’
Craete the /tmp directory in given location./var/tmp
change the permission in given directory
both directory available on /home/upoload/recording
mkodir upload
chmode 777 upload
cd upload
mkdir recording
chmode 777 recording
For HTML form that allow users to choose the Vedeo File you want to upload:
Save the file index.php name
<!DOCTYPE html> <html> <body> <head> <title> EasyDial -- FILE UPLOAD </title> </head> <body> <form action="upload.php" method="post" enctype="multipart/form-data"> <fieldset style="width:35%"> <legend>File Upload :</legend> <table border="0"> <tr> <td><h3>Select File to upload:</h3></td></tr> <tr><td> <input type="file" name="Upload" id="fileToUpload" ></td> <td><input type="submit" value="Upload_File" name="submit"></td></tr> </fieldset> </form> </body> </html>
Make sure that the form uses method=”post”
The form also needs the following attribute: enctype=”multipart/form-data”.
It specifies which content-type to use when submitting the form.
The type=”file” attribute of the <input> tag shows the input field as a file-select control, with a “Browse” button next to the input control.
Save the file Upload.php name:
<?php $path = "/home/upload/recording/"; $target_file = $path . basename($_FILES["Upload"]["name"]); $uploadOk = 1; // Check if file empty if (empty($_FILES["Upload"]["name"] )) { echo "Sorry,no file select."; $uploadOk = 0; echo nl2br("\n"); echo "<a href ='index.php'>".'Home Page'."</a>" ; exit; } $FileType = pathinfo($target_file,PATHINFO_EXTENSION); // Check if file is a actual FILE if(isset($_POST["submit"])) { $check = getimagesize($_FILES["Upload"]["tmp_name"]); if($check == false) { //echo "Audio File - " . $check["mime"] . "."; $uploadOk = 1; } else { echo "File is other formate."; $uploadOk = 0; } } // Check if file already exists if (file_exists($target_file)) { echo "Sorry, file already exists."; $uploadOk = 0; } // Check file size if ($_FILES["fileToUpload"]["size"] < 5000) { echo "Sorry, your file is too small."; $uploadOk = 0; } // Allow certain file formats if($FileType != "wav" && $FileType != "mp3") { echo "Sorry, only wav file formate allow."; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { echo "Sorry, your file was not uploaded."; // if everything is ok, try to upload file } else { if(move_uploaded_file($_FILES['Upload']['tmp_name'], $path . $_FILES['Upload']['name'] )) { echo "The file ". basename( $_FILES["Upload"]["name"]). "has been uploaded"; } else { echo "Sorry, there was an error uploading your file "; } } echo nl2br("\n"); echo "<a href ='index.php'>".'Home Page'."</a>" ; ?>