1

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>

Mohit Kumar
  • 952
  • 2
  • 7
  • 18
Rohan Jain
  • 31
  • 1
  • 1
  • 9
  • Look in php.ini for `upload_max_filesize` http://stackoverflow.com/questions/2184513/php-change-the-maximum-upload-file-size – Mihai Sep 21 '14 at 09:14
  • I think the best thing for you is to check out a video tutorial like: https://www.youtube.com/watch?v=PRCobMXhnyw&list=PLfdtiltiRHWFVuW0b79nLbW25P340j1dT. There are so many things wrong with this code. 1) hardcoded links 2) `mysql_*` instead of `mysqli_*` or `PDO` 3) using `if($field == '')` instead of `if(empty($field))` 4) using `isset($_SESSION[])` instead of `!empty($_SESSION)` (`empty()` does the same as `isset()` but also checks if it is empty or not). To come to your question like @Mihai said look in the php.ini for max upload sizes there are a couple of them that needs to be changed – SuperDJ Sep 21 '14 at 09:17
  • i m nt able to find php.ini ! – Rohan Jain Sep 21 '14 at 09:28
  • Google php.ini location in Ubuntu,or whatever is your operating system,or if you use xampp search for that. – Mihai Sep 21 '14 at 09:31
  • i m using mac os. and i just changed the upload value to 200 MB. i m still out of luck. – Rohan Jain Sep 21 '14 at 09:40
  • You need to restart apache after making the changes. – Mihai Sep 21 '14 at 14:52

2 Answers2

1

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).

Robin K
  • 437
  • 6
  • 17
0

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.

Beat
  • 1,337
  • 15
  • 30