我已经建立了一个文件上传表格。 我把: * Txt文件大小限制:100MB * Img文件大小限制:100MB *音频文件大小限制:100MB *视频文件大小限制:100MB
我没有上传任何大于100MB的内容,但收到消息: “警告:10835360字节的POST内容长度超出了第0行中Unknown中的8388608字节的限制。”
对于每种文件类型,如果任何文件大小超出限制,我都会写回自定义错误消息。我没有收到我的自定义错误消息。因此,相信我没有超出任何文件的大小限制。另外,我检查了每个文件的大小,它们不超过100MB。
我不知道php指的是哪种文件。它指的是哪个文件?
使用小于100MB但没有运气的不同文件进行了几次测试。
<?php
//ERROR REPORTING CODES.
//declare(strict_types=1);
ini_set('display_errors', '0');
ini_set('display_startup_errors', '0');
error_reporting(0);
//mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$conn = mysqli_connect("localhost","root","","followingbrowser");
if (!$conn)
{
$error = mysqli_connect_error();
$errno = mysqli_connect_errno();
print "$errno: $error\n";
exit();
}
$error_msg = array();
$text_allowed_ext = array('pdf','txt','doc','docx');
$video_allowed_ext = array('mp4','wav','ogg','flv','wmv','avi');
$img_allowed_ext = array('jpeg','jpg','png','gif');
$audio_allowed_ext = array('mp3','wav');
$img_mime_type = array('image/png','image/gif','image/jpeg','image/jpg');
$text_mime_type = array('application/pdf','text/plain','application/msword','application/vnd.openxmlformats-officedocument.wordprocessingml.document');
$video_mime_type = array('video/mp4','video/wav','video/ogg','video/flv','video/wmv','video/avi');
$audio_mime_type = array('audio/mpeg3', 'audio/x-mpeg-3','audio/mpeg','audio/wav','application/octet-stream');
if($_SERVER["REQUEST_METHOD"] == "POST"){
$error = 0 ;
//var_dump($_FILES); //For debugging.
//Check whether the file was uploaded or not without any errors.
if(!isset($_FILES["id_verification_video_file"]) || !isset($_FILES['id_verification_txt_file']) || !isset($_FILES['id_verification_audio_file']) || !isset($_FILES['id_verification_img_file'])){
$error_msg['all'] = '<p class="text-danger">Please select all fields</p>';
$error = 1;
}else{
$txt_file = $_FILES["id_verification_txt_file"]["name"];
$video_file = $_FILES["id_verification_video_file"]["name"];
$audio_file = $_FILES["id_verification_audio_file"]["name"];
$img_file = $_FILES["id_verification_img_file"]["name"];
//filters to check the file type extensions
if(!in_array(pathinfo($txt_file, PATHINFO_EXTENSION),$text_allowed_ext)){
$error_msg['txt_error']= '<p class="text-danger">Invalid Extensions.Only PDF,text and DOC files are allowed';
$error = 1;
}
if(!in_array(pathinfo($video_file, PATHINFO_EXTENSION),$video_allowed_ext)){
$error_msg['video_error'] = '<p class="text-danger">Invalid Extensions.Only MP4,WAV,OGG,FLV,WMV and AVI files are allowed';
$error = 1;
}
if(!in_array(pathinfo($audio_file, PATHINFO_EXTENSION),$audio_allowed_ext)){
$error_msg['audio_error']= '<p class="text-danger">Invalid Extensions.Only MP3 and WAV files are allowed';
$error = 1;
}
if(!in_array(pathinfo($img_file, PATHINFO_EXTENSION),$img_allowed_ext)){
$error_msg['img_error']= '<p class="text-danger">Invalid Extensions.Only JPG,JPEG,PNG and GIF files are allowed';
$error = 1;
}
//checking mime type
if(!in_array(mime_content_type($_FILES["id_verification_img_file"]['tmp_name']),$img_mime_type)){
$error_msg['img_error']= '<p class="text-danger">Invalid Extensions.Only JPG,JPEG,PNG and GIF files are allowed';
$error = 1;
}
if(!in_array(mime_content_type($_FILES["id_verification_txt_file"]['tmp_name']),$text_mime_type)){
$error_msg['txt_error']= '<p class="text-danger">Invalid Extensions.Only PDF,text and DOC files are allowed';
$error = 1;
}
if(!in_array(mime_content_type($_FILES["id_verification_video_file"]['tmp_name']),$video_mime_type)){
$error_msg['video_error'] = '<p class="text-danger">Invalid Extensions.Only MP4,WAV,OGG,FLV,WMV and AVI files are allowed';
$error = 1;
}
if(!in_array(mime_content_type($_FILES["id_verification_audio_file"]['tmp_name']),$audio_mime_type)){
$error_msg['audio_error']= '<p class="text-danger">Invalid Extensions.Only MP3 and WAV files are allowed';
$error = 1;
echo mime_content_type($_FILES["id_verification_audio_file"]['tmp_name']);
}
//checking file size using filesize function
if(filesize($_FILES['id_verification_txt_file']) > 100000000){
$error_msg['txt_file_size_err'] = '<p class="text-danger">File size is greater then 100MB.File size should not exceed the 100MB';
$error = 1;
}
if(filesize($_FILES['id_verification_video_file']) > 100000000){
$error_msg['video_file_size_err'] = '<p class="text-danger">File size is greater then 100MB.File size should not exceed the 100MB';
$error = 1;
}
if(filesize($_FILES['id_verification_audio_file']) > 100000000){
$error_msg['audio_file_size_err'] = '<p class="text-danger">File size is greater then 100MB.File size should not exceed the 100MB';
$error = 1;
}
if(filesize($_FILES['id_verification_img_file']) > 100000000){
$error_msg['img_file_size_err'] = '<p class="text-danger">File size is greater then 100MB.File size should not exceed the 100MB';
$error = 1;
}
//checking if there are no errors
if($error == 0){
$user = $user; //username here
$db_user = 'followingbrowser_user'; //Has to be in quotes.
//Feed Id Verification Video File Upload Directory path.
$directory_path = 'uploads/id_verifications/';
//Make Directory under $user in 'uploads/videos/id_verifications' Folder.
$directory_path_and_user_dir = $directory_path.$user;
if(!is_dir($directory_path_and_user_dir)){
$db_user = 'followingbrowser_user'; //Has to be in quotes.
$mode = 0755;
mkdir($directory_path_and_user_dir,$mode, TRUE); //This line is correct and working even without quoting $mode.
}
//making directories of every files for respective user
$video_directory = $directory_path_and_user_dir.'/videos';
$audio_directory = $directory_path_and_user_dir.'/audios';
$text_directory = $directory_path_and_user_dir.'/text';
$img_directory = $directory_path_and_user_dir.'/imgs';
if(!is_dir($video_directory)){
$db_user = 'followingbrowser_user'; //Has to be in quotes.
$mode = 0755;
mkdir($video_directory,$mode, TRUE); //This line is correct and working even without quoting $mode.
}
if(!is_dir($audio_directory)){
$db_user = 'followingbrowser_user'; //Has to be in quotes.
$mode = 0755;
mkdir($audio_directory,$mode, TRUE); //This line is correct and working even without quoting $mode.
}
if(!is_dir($text_directory)){
$db_user = 'followingbrowser_user'; //Has to be in quotes.
$mode = 0755;
mkdir($text_directory,$mode, TRUE); //This line is correct and working even without quoting $mode.
}
if(!is_dir($img_directory)){
$db_user = 'followingbrowser_user'; //Has to be in quotes.
$mode = 0755;
mkdir($img_directory,$mode, TRUE); //This line is correct and working even without quoting $mode.
}
//uploading the videos files
$upload_file_err = 0;
//video files
$video_file_name = $_FILES["id_verification_video_file"]["name"];
$video_file_tmp = $_FILES["id_verification_video_file"]["tmp_name"];
$video_file_type = $_FILES["id_verification_video_file"]["type"];
$video_file_size = $_FILES["id_verification_video_file"]["size"];
$video_file_error = $_FILES['id_verification_video_file']['error'];
$video_file_ext = pathinfo($video_file, PATHINFO_EXTENSION);
//audio files
$audio_file_name = $_FILES["id_verification_audio_file"]["name"];
$audio_file_tmp = $_FILES["id_verification_audio_file"]["tmp_name"];
$audio_file_type = $_FILES["id_verification_audio_file"]["type"];
$audio_file_size = $_FILES["id_verification_audio_file"]["size"];
$audio_file_error = $_FILES['id_verification_audio_file']['error'];
$audio_file_ext = pathinfo($audio_file, PATHINFO_EXTENSION);
//image files
$img_file_name = $_FILES["id_verification_img_file"]["name"];
$img_file_tmp = $_FILES["id_verification_img_file"]["tmp_name"];
$img_file_type = $_FILES["id_verification_img_file"]["type"];
$img_file_size = $_FILES["id_verification_img_file"]["size"];
$img_file_error = $_FILES['id_verification_img_file']['error'];
$img_file_ext = pathinfo($img_file, PATHINFO_EXTENSION);
//text files
$txt_file_name = $_FILES["id_verification_txt_file"]["name"];
$txt_file_tmp = $_FILES["id_verification_txt_file"]["tmp_name"];
$txt_file_type = $_FILES["id_verification_txt_file"]["type"];
$txt_file_size = $_FILES["id_verification_txt_file"]["size"];
$txt_file_error = $_FILES['id_verification_txt_file']['error'];
$txt_file_ext = pathinfo($txt_file, PATHINFO_EXTENSION);
$video_user_file_dir = $video_directory.'/'.$video_file_name;
$audio_user_file_dir = $audio_directory.'/'.$audio_file_name;
$img_user_file_dir = $img_directory.'/'.$img_file_name;
$txt_user_file_dir = $text_directory.'/'.$txt_file_name;
//$audio_user_file_dir = $audio_directory.'/'.$file_name;
$upload_err = 0;
//uploading video file
if(file_exists($video_user_file_dir)){
$error_msg['upload_video_error'] = '<p class="text-danger">You have already uploaded a video file to verify your ID! No need to upload and verify again</p>';
$upload_err = 1;
}
if(file_exists($audio_user_file_dir)){
$error_msg['upload_audio_error'] = '<p class="text-danger">You have already uploaded a Audio file to verify your ID! No need to upload and verify again</p>';
$upload_err = 1;
}
if(file_exists($img_user_file_dir)){
$error_msg['upload_img_error'] = '<p class="text-danger">You have already uploaded a Image file to verify your ID! No need to upload and verify again</p>';
$upload_err = 1;
}
if(file_exists($txt_user_file_dir)){
$error_msg['upload_txt_error'] = '<p class="text-danger">You have already uploaded a Text file to verify your ID! No need to upload and verify again</p>';
$upload_err = 1;
}
if($upload_err == 0){
if(is_uploaded_file($_FILES["id_verification_video_file"]["tmp_name"]) && is_uploaded_file($_FILES["id_verification_audio_file"]["tmp_name"]) && is_uploaded_file($_FILES["id_verification_txt_file"]["tmp_name"]) && is_uploaded_file($_FILES["id_verification_img_file"]["tmp_name"])){
if(move_uploaded_file($video_file_tmp,$video_user_file_dir)){
// rename($video_user_file_dir , $video_directory.'/'.$user.'_id_verfication.'.$video_file_ext );
}
if(move_uploaded_file($audio_file_tmp,$audio_user_file_dir)){
// rename($audio_user_file_dir , $audio_directory.'/'.$user.'_id_verfication.'.$audio_file_ext );
}
if(move_uploaded_file($txt_file_tmp,$txt_user_file_dir)){
//rename($txt_user_file_dir , $text_directory.'/'.$user.'_id_verfication.'.$txt_file_ext );
}
if(move_uploaded_file($img_file_tmp,$img_user_file_dir)){
//rename($img_user_file_dir , $img_directory.'/'.$user.'_id_verfication.'.$img_file_ext );
}
$success_msg = 'Files has been uploaded successfully';
}else{
$error_msg = 'Files failed in uploading! File upload attack could be the reason';
}
}
}
}
}
?>
<?php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Confirm Id Upload </title>
</head>
<body>
<section class="section confim-id-page">
<div class="container">
<div class="page-wrapper">
<div class="page-title">
<h3><?php $site_name ?> ID Video Verification Form</h3>
<p>Please upload your video for your ID Confirmation</p>
</div>
<?php if(isset($error_msg) && !empty($error_msg)){ echo $error_msg['all'];} ?>
<?php if(isset($error_msg['upload_video_error']) && !empty(
$error_msg['upload_video_error'])){ echo $error_msg['upload_video_error'];} ?>
<?php if(isset($success_msg) && !empty($success_msg)){ echo '<p class="alert-success">'.$success_msg.'</p>';} ?>
<?php if(isset($error_msg) && !empty($error_msg)){ echo '<p class="alert-success">'.$error_msg.'</p>';} ?>
<form method="POST" action="" enctype="multipart/form-data" id="videoUploadForm" name="videoUploadForm">
<div class="form-group">
<label class="control-label">Text File</label>
<div class="fileInput">
<input type="file" name="id_verification_txt_file" id="id_verification_txt_file" class="form-control custom-file-input" value="uploaded 'Id Verification Text File.'" required />
</div>
<?php if(isset($error_msg['txt_error']) && $error_msg['txt_error']!=''){ echo $error_msg['txt_error']; } ?>
<?php if(isset($error_msg['txt_file_size_err']) && $error_msg['txt_file_size_err']!=''){ echo $error_msg['txt_file_size_err']; } ?>
<?php if(isset($error_msg['upload_txt_error']) && $error_msg['upload_txt_error']!=''){ echo $error_msg['upload_txt_error']; } ?>
<p id="error1" class="text-danger" style="display:none; color:#FF0000;">
Invalid Format! Only Format of text, doc and pdf files extension are allowed.
</p>
<p id="error2" class="text-danger" style="display:none; color:#FF0000;">
Maximum File Size Limit is 100MB.
</p>
</div>
<div class="form-group">
<label class="control-label">Video File</label>
<div class="fileInput">
<input type="file" name="id_verification_video_file" id="id_verification_video_file" class="form-control custom-file-input" value="uploaded 'Id Verification Video File.'" required>
</div>
<?php if(isset($error_msg['video_error']) && $error_msg['video_error']!=''){ echo $error_msg['video_error']; } ?>
<?php if(isset($error_msg['video_file_size_err']) && $error_msg['video_file_size_err']!=''){ echo $error_msg['video_file_size_err']; } ?>
<?php if(isset($error_msg['upload_video_error']) && $error_msg['upload_video_error']!=''){ echo $error_msg['upload_video_error']; } ?>
<p id="error3" class="text-danger" style="display:none; color:#FF0000;">
Invalid Format! Only Format of mp4,ogg,wmv,flv and avi and wav files extension are allowed.
</p>
<p id="error4" class="text-danger" style="display:none; color:#FF0000;">
Maximum File Size Limit is 100MB.
</p>
</div>
<div class="form-group">
<label class="control-label">Audio File</label>
<div class="fileInput">
<input type="file" name="id_verification_audio_file" id="id_verification_audio_file" class="form-control custom-file-input" value="uploaded 'Id Verification Audio File.'" required />
</div>
<?php if(isset($error_msg['audio_error']) && $error_msg['audio_error']!=''){ echo $error_msg['audio_error']; } ?>
<?php if(isset($error_msg['audio_file_size_err']) && $error_msg['audio_file_size_err']!=''){ echo $error_msg['audio_file_size_err']; } ?>
<?php if(isset($error_msg['upload_audio_error']) && $error_msg['upload_audio_error']!=''){ echo $error_msg['upload_audio_error']; } ?>
<p id="error5" class="text-danger" style="display:none; color:#FF0000;">
Invalid Format! Only Format of mp3 and wav files extension are allowed.
</p>
<p id="error6" class="text-danger" style="display:none; color:#FF0000;">
Maximum File Size Limit is 100MB.
</p>
</div>
<div class="form-group">
<label class="control-label">Image File</label>
<div class="fileInput">
<input type="file" name="id_verification_img_file" id="id_verification_img_file" class="form-control custom-file-input" value="uploaded 'Id Verification Image File.'" required />
</div>
<?php if(isset($error_msg['img_error']) && $error_msg['img_error']!=''){ echo $error_msg['img_error']; } ?>
<?php if(isset($error_msg['img_file_size_err']) && $error_msg['img_file_size_err']!=''){ echo $error_msg['img_file_size_err']; } ?>
<?php if(isset($error_msg['upload_img_error']) && $error_msg['upload_img_error']!=''){ echo $error_msg['upload_img_error']; } ?>
<p id="error7" class="text-danger" style="display:none; color:#FF0000;">
Invalid Format! Only Format of jpeg,png,jpeg and gif files extension are allowed.
</p>
<p id="error8" class="text-danger" style="display:none; color:#FF0000;">
Maximum File Size Limit is 100MB.
</p>
</div>
<br/>
<button type="submit" id="upload" class="btn btn-submit" name="id_verification_video_file_submit">Submit</button>
</form>
</div>
</div>
</section>
</body>
</html>
<!--
<?php
include 'footer_account.php'; //Required on all webpages of the Account.
?> -->
<script type="text/javascript">
$(function(){
$('#id_verification_txt_file').bind('change', function() {
if ($('button:submit').attr('disabled',false)){
$('button:submit').attr('disabled',true);
}
var ext = $('#id_verification_txt_file').val().split('.').pop().toLowerCase();
if ($.inArray(ext, ['txt','doc','pdf','docx']) == -1){
$('#error1').slideDown("slow");
$('#error2').slideUp("slow");
a=0;
}else{
var text_file = (this.files[0].size);
if (text_file > 100000000){
$('#error2').slideDown("slow");
a=0;
}else{
a=1;
$('#error2').slideUp("slow");
}
$('#error1').slideUp("slow");
if (a==1){
$('button:submit').attr('disabled',false);
}
}
});
/*---- Video files extension ---*/
$('#id_verification_video_file').bind('change', function() {
if ($('button:submit').attr('disabled',false)){
$('button:submit').attr('disabled',true);
}
var ext = $('#id_verification_video_file').val().split('.').pop().toLowerCase();
if ($.inArray(ext, ['mp4','wav','ogg','flv','wmv','avi']) == -1){
$('#error3').slideDown("slow");
$('#error4').slideUp("slow");
a=0;
}else{
var text_file = (this.files[0].size);
if (text_file > 100000000){
$('#error4').slideDown("slow");
a=0;
}else{
a=1;
$('#error4').slideUp("slow");
}
$('#error3').slideUp("slow");
if (b==1){
$('button:submit').attr('disabled',false);
}
}
});
/*---- Audio Files extension ---*/
$('#id_verification_audio_file').bind('change', function() {
if ($('button:submit').attr('disabled',false)){
$('button:submit').attr('disabled',true);
}
var ext = $('#id_verification_audio_file').val().split('.').pop().toLowerCase();
if ($.inArray(ext, ['mp3','wav']) == -1){
$('#error5').slideDown("slow");
$('#error6').slideUp("slow");
c=0;
}else{
var audio_file = (this.files[0].size);
if (audio_file > 100000000){
$('#error6').slideDown("slow");
c=0;
}else{
c=1;
$('#error6').slideUp("slow");
}
$('#error5').slideUp("slow");
if (c==1){
$('button:submit').attr('disabled',false);
}
}
});
/*--- Image files extension are allowed ---*/
$('#id_verification_img_file').bind('change', function() {
if ($('button:submit').attr('disabled',false)){
$('button:submit').attr('disabled',true);
}
var ext = $('#id_verification_img_file').val().split('.').pop().toLowerCase();
if ($.inArray(ext, ['jpg','png','gif','jpeg']) == -1){
$('#error7').slideDown("slow");
$('#error8').slideUp("slow");
d=0;
}else{
var img_file = (this.files[0].size);
if (img_file > 100000000){
$('#error8').slideDown("slow");
d=0;
}else{
d=1;
$('#error8').slideUp("slow");
}
$('#error5').slideUp("slow");
if (d==1){
$('button:submit').attr('disabled',false);
}
}
});
});
</script>