Reputation: 31
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>
Upvotes: 1
Views: 13478
Reputation: 437
Change the following settings according to your needs:
max_execution_time = 1800 #Time in seconds your script may run
memory_limit = 512M #max amount of memory a script may use
post_max_size = 128M #Maximum size of POST data that PHP will accept
file_uploads = On # Will never work if this isn't set to On
upload_max_filesize = 256M the maximum size any given uploaded file may have
Don't forget to reload apache (or restart if you want).
Upvotes: 1
Reputation: 1380
There is a file size limit for uploads and it's probably set to 100MB in your case.
See PHP change the maximum upload file size on how to change the limit.
EDIT: You must change these settings in the php.ini, you can't change them in your code:
If you can't change your php.ini, you're out of luck. You cannot change these values at run-time; uploads of file larger than the value specified in php.ini will have failed by the time execution reaches your call to ini_set.
Upvotes: 0