使用 PHP 上传 mp4 文件

Uploading mp4 files using PHP(使用 PHP 上传 mp4 文件)
本文介绍了使用 PHP 上传 mp4 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

还是一样的错误

视频/mp4无效文件

推荐答案

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

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

  • post_max_size
  • upload_max_filesize
  • memory_limit

参见处理文件上传:常见问题 其中详细解释了这一点以及如何计算这些值.

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

这篇关于使用 PHP 上传 mp4 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)