gpt4 book ai didi

php - 使用 PHP 上传 mp4 文件

转载 作者:行者123 更新时间:2023-12-05 03:14:29 25 4
gpt4 key购买 nike

我可以使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com