使用 PHP 上传 mp4 文件

编程入门 行业动态 更新时间:2024-10-22 16:30:32
本文介绍了使用 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 文件

本文发布于:2023-11-24 21:10:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1626840.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上传   文件   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!