<?php
error_reporting(1);
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "demo";
$conn = new mysqli($servername, $username, $password, $dbname);
$target_dir = "test_upload/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
if(isset($_POST["upd"]))
{
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if($imageFileType != "mp4" && $imageFileType != "avi" && $imageFileType != "mov" && $imageFileType != "3gp" && $imageFileType != "mpeg")
{
echo "File Format Not Suppoted";
}
else
{
$video_path=$_FILES['fileToUpload']['name'];
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],$target_file);
$sql = "INSERT INTO video (video_name) VALUES ('$video_path')";
$result = $conn->query($sql);
echo "uploaded ";
}
}
if(isset($_POST["disp"]))
{
$sql = "select * from video";
$result = $conn->query($sql);
while($row=mysqli_fetch_array($result,MYSQLI_NUM))
{ ?>
<video width="300" height="200" controls>
<source src="test_upload/<?php echo $row[1]; ?>" type="video/mp4">
</video>
<?php
}
} ?>
<html>
<body>
<form method="post" enctype="multipart/form-data">
<table border="1">
<tr>
<td>
Upload Video
</td>
</tr>
<tr>
<td>
<input type="file" name="fileToUpload"/>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Uplaod Video" name="upd"/>
<input type="submit" value="Display Video" name="disp"/>
</td>
</tr>
</table>
</form>
</body>
I am trying to upload the video file to server which supports ffmpeg , for small size videos like 4 to 5 mb it works fine , but when i am trying to upload the video more than 15mb, it takes too much time for upload.How to compress the size of the video file with out losing the quality while uploading to server using php?