I have got a college project to create a virtual classroom where teachers can upload video lectures that students can access.
I'm trying to save path of video into database, saving the video into a folder and then trying to access it.
Sometimes videos are not uploaded. When trying to save video more than 100 mb, the path is not able to save in the database. If the video size is smaller then the path is saved to database.
I don't understand what the problem is because I'm trying to save path not the video.
*************** THIS IS MY UPLOAD SCRIPT***********
<?php
session_start();
require("/Applications/MAMP/htdocs/conn.php");
function is_valid_type($file)
{
$valid_types = array('video/mp4', 'video/mpeg', 'video/mpg', 'audio/mpeg');
if (in_array($file['type'], $valid_types))
return 1;
return 0;
}
function showContents($array)
{
echo "<pre>";
print_r($array);
echo "</pre>";
}
$TARGET_PATH = "/Applications/MAMP/htdocs/home/";
$id = $_POST['id'];
$name = $_POST['name'];
$video_path = $_FILES['video_path'];
$TARGET_PATH .= $video_path['name'];
if ( $id == "" || $name == "" || $video_path['name'] == "" )
{
$_SESSION['error'] = "All fields are required";
header("Location: index.php");
exit;
}
if (!is_valid_type($video_path))
{
$_SESSION['error'] = "You must upload a jpeg, gif,mp4 or bmp";
header("Location: index.php");
exit;
}
if (file_exists($TARGET_PATH))
{
$_SESSION['error'] = "A file with that name already exists";
header("Location: index.php");
exit;
}
if (move_uploaded_file($video_path['tmp_name'], $TARGET_PATH))
{
$sql = "insert into video (id, name, video_path) values ('$id', '$name', '" . $video_path['name'] . "')";
$result = mysql_query($sql) or die ("Could not insert data into DB: " . mysql_error());
header("Location: http://localhost:8888/htdocs/images.php");
exit;
}
else
{
$_SESSION['error'] = "Could not upload file. Check read/write persmissions on the directory";
header("Location: index.php");
exit;
}
?>
*******************this is my displaying script**************
<?php
require("/Applications/MAMP/htdocs/conn.php");
?>
<html>
<head>
<title>tutorial</title>
</head>
<body>
<div>
<?php
$sql = "select * from video";
$result = mysql_query($sql) or die ("Could not access DB: " . mysql_error());
while ($row = mysql_fetch_assoc($result))
{
$src=$row['video_path'];
$path="http://localhost:8888/home/";
$home=$path.$src;
//echo "<video src=\"$home" ."\" height=\"200\" width=\"200\"/>";
echo $row['id'] . " " . $row['name'] . "<br />";
echo "</p>";
?>
<video width="320" height="240" controls>
<source src="<?php echo $home ?>" type="video/mp4" >
</video>
<?php
}
?>
</div>
</body>
</html>
********************this is my form script**********
<?php
session_start();
?>
<html>
<head>
<title>Dream in code tutorial</title>
<style type="text/css">
label
{
float: left;
text-align: right;
margin-right: 10px;
width: 100px;
color: black;
}
#submit
{
float: left;
margin-top: 5px;
position: relative;
left: 110px;
}
#error
{
color: red;
font-weight: bold;
font-size: 16pt;
}
</style>
</head>
<body>
<div>
<?php
if (isset($_SESSION['error']))
{
echo "<span id=\"error\"><p>" . $_SESSION['error'] . "</p></span>";
unset($_SESSION['error']);
}
?>
<form action="upload.php" method="post" enctype="multipart/form-data">
<p>
<label>ID</label>
<input type="text" name="id" /><br />
<label>Video Name</label>
<input type="text" name="name" /><br />
<label>Upload Image</label>
<input type="file" name="video_path" /><br />
<input type="hidden" name="MAX_FILE_SIZE" value="100000000" />
<input type="submit" id="submit" value="Upload" />
</p>
</form>
</div>