php - 使用 PHP 上传 mp4 文件

标签 php video upload mp4

我可以使用 PHP 上传脚本上传 png/jpegs/图像,但无法在我的本地服务器上上传 mp4 文件。脚本未显示任何错误。

<?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";
    }
    ?>

还是一样的错误

video/mp4Invalid file

最佳答案

如果您的代码没有任何错误,请确保增加 post_max_size AND load_max_filesize AND memory_limit

参见 Handling file uploads: Common Pitfals其中详细解释了这一点以及如何计算这些值。

关于php - 使用 PHP 上传 mp4 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24362903/

相关文章:

javascript - 如何通过 URL 发送数组并在 PHP 中提取它?

flash - Flash上​​传图片调整大小客户端

php - SQLSTATE[42000] : Syntax error or access violation

php - 如何在新行上编写laravel sql查询子句

android - 在 android 中使用 silicompressor 的视频压缩不起作用

javascript - 支持流式传输 m4v 文件的 Flash 视频播放器

android - 媒体播放器-NuPlayerRenderer : possible video time jump of x ms

python - 403 客户端错误 : Invalid or non-existent authentication information while uploading to Pypi with twine

html - 是否可以专门要求用户使用 HTML5 上传图片?

php - 带有 PHP 的多个浏览器选项卡和 "Back"按钮