Uploading mp4 files using PHP

14,474

Solution 1

If your code does not have any errors, please make sure to increase post_max_size AND load_max_filesize AND memory_limit

See Handling file uploads: Common Pitfals which explains this in detail and how to calculate the values.

Solution 2

you have to modify the POST max size, and the file upload size in your php.ini

It should look like this if you want to disable the limit:

; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; http://php.net/post-max-size
post_max_size=0

And of course the file limit:

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize=1000M
Share:
14,474
nickalchemist
Author by

nickalchemist

Mobile | Product | Blogger | Javascript | UX

Updated on September 02, 2022

Comments

  • nickalchemist
    nickalchemist over 1 year

    I am able to upload png/jpegs/images using PHP upload script but am not able to upload mp4 files on my local server. Script is not displaying any error.

    <?php
    ini_set('display_startup_errors',1);
    ini_set('display_errors',1);
    error_reporting(-1);
    //include authentication here/ Gmail is good solution for now
    //check if it's not allowing any other extenstion other than MP4
    $allowedExts = array("gif", "jpeg", "jpg", "png","mp4");
    $temp = explode(".", $_FILES["file"]["name"]);
    print_r($_FILES["file"]["type"]);
    $extension = end($temp);
    if ((($_FILES["file"]["type"] == "image/gif")
    || ($_FILES["file"]["type"] == "image/jpeg")
    || ($_FILES["file"]["type"] == "image/jpg")
    || ($_FILES["file"]["type"] == "image/pjpeg")
    || ($_FILES["file"]["type"] == "image/x-png")
    || ($_FILES["file"]["type"] == "image/png"))
    || ($_FILES["file"]["type"] == "video/mp4"))
    && ($_FILES["file"]["size"] < 200000)
    && in_array($extension, $allowedExts)) {
      if ($_FILES["file"]["error"] > 0) {
        echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
      } else {
        echo "Upload: " . $_FILES["file"]["name"] . "<br>";
        echo "Type: " . $_FILES["file"]["type"] . "<br>";
        echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
        echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
        if (file_exists("uploads/" . $_FILES["file"]["name"])) {
          echo $_FILES["file"]["name"] . " already exists. ";
        } else {
          move_uploaded_file($_FILES["file"]["tmp_name"],
          "uploads/" . $_FILES["file"]["name"]);
          echo "Stored in: " . "uploads/" . $_FILES["file"]["name"];
        }
      }
    } else {
      echo "Invalid file";
    }
    ?>
    enter code here
    changed my code to this
    
    
     <?php
        ini_set('display_startup_errors',1);
        ini_set('display_errors',1);
        error_reporting(-1);
        //include authentication here/ Gmail is good solution for now
        //check if it's not allowing any other extenstion other than MP4
        $allowedExts = array("gif", "jpeg", "jpg", "png","mp4");
        $temp = explode(".", $_FILES["file"]["name"]);
        print_r($_FILES["file"]["type"]);
        $extension = end($temp);
        if (($_FILES["file"]["size"] < 200000)) {
          if ($_FILES["file"]["error"] > 0) {
            echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
          } else {
            echo "Upload: " . $_FILES["file"]["name"] . "<br>";
            echo "Type: " . $_FILES["file"]["type"] . "<br>";
            echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
            echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
            if (file_exists("uploads/" . $_FILES["file"]["name"])) {
              echo $_FILES["file"]["name"] . " already exists. ";
            } else {
              move_uploaded_file($_FILES["file"]["tmp_name"],
              "uploads/" . $_FILES["file"]["name"]);
              echo "Stored in: " . "uploads/" . $_FILES["file"]["name"];
            }
          }
        } else {
          echo "Invalid file";
        }
        ?>
    

    still same error

    video/mp4Invalid file