Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
856 views
in Technique[技术] by (71.8m points)

video - Uploading mp4 files using PHP

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...