我有一个表单,用户可以通过该表单上传视频并将其存储在服务器文件夹中
<form action="insertvideo.php" method="post" class="form-horizontal form-bordered" enctype="multipart/form-data">
<input type="file" name="file" id="file" />
<button type="submit" value="submit" name="submit" class="btn green"><i class="fa fa-check"></i> Submit</button>
</form>
insertvideo.php page
<?php
$allowedExts = array("mp3", "mp4", "wma");
$extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
if ((($_FILES["file"]["type"] == "video/mp4")
|| ($_FILES["file"]["type"] == "audio/mp3")
|| ($_FILES["file"]["type"] == "audio/wma"))
&& 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("extra/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"extra/" . $_FILES["file"]["name"]);
echo "Stored in: " . "extra/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>
我有2个.MP4格式的视频,一个尺寸较小,另一个尺寸较大。出于测试目的,我没有放置任何检查视频大小的代码,但仍然没有上传更大尺寸的视频。
任何人都可以告诉为什么会发生这种情况
答案 0 :(得分:1)
<?php
$new_path = '.extra/';
$target_file = $new_path . basename($_FILES["file"]["name"]);
$ext = pathinfo($target_file,PATHINFO_EXTENSION);
$allowed_ext = array("mp3", "mp4", "wma");
if (in_array($target_file, $allowed_ext)) {
if(file_exists("extra/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"], "extra/".$_FILES["file"]["name"].$ext);
echo "Stored in: " . "extra/" . $_FILES["file"]["name"];
}
}
else
{
echo "Invalid file";
}
?>
并在php.ini
file_uploads=On
upload_max_filesize=20M
答案 1 :(得分:0)
在php.ini中增加最大上传大小和帖子大小
ini_set('upload_max_filesize', '400M');
post_max_size = 10M