本文介绍了使用 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 文件
发布评论