我正在使用laravel 5.2 php5.6 fpm。我有可以上传视频文件的表格。如果我上传小视频,它上传文件并显示其余输入,则一切正常,但是,如果我尝试上传较大的视频(例如4MB),则整个输入为空,它仅返回null
。因此未提供任何输入。
我的php.ini
upload_max_filesize = 200M
post_max_size = 200M
memory_limit = 800M # increased it, just to make sure its not causing the problem
我重述了服务器,nginx,php-fpm进程,清除了缓存,但是相同。
我用js
FormData
发送数据$("input.uploaded_photos,input.uploaded_videos").change(function(){
var input = this;
var albumId = $("[name='id']").val();
var albumType = $("[name='type']:checked").val();
//only continue if currently selected album type matches the current input field
if($(input).attr('data-type') == albumType){
if (input.files && input.files.length) {
var selectedType = $(input).parents('form').find("[name='type']:checked").val();
var existingUploads = $('.selling-album-upload-' + selectedType + 's-row .selling-album-upload').length;
var totalResultingUploads = input.files.length + existingUploads;
var selectedPackCount = parseInt($(input).parents('form').find("[name='picture_pack']").val());
var dataform = new FormData();
for(var iFile in input.files){
if(!isNaN(iFile)){//otherwise we'll get 'length' and 'file' as keys too
var file = input.files[iFile];
dataform.append(input.name, file, file.name);
}
}
dataform.append('album_id', albumId);
dataform.append('type', albumType);
$.ajax({
url: '/myurl'
type: 'POST',
data: dataform,
async: false,//false, otherwise it creates a GET Request
success: function (data) {
// do something
},
cache: false,
contentType: false,
processData: false
});
}
}
});
如果我上传“大”视频
Input::all()
返回null,则为空白,我认为问题应该出在js中。无论如何,这里是PHP代码:public function postAddSellingAlbumUpload(){
$album_id = Input::get('album_id');
$type = Input::get('type');
$existing_uploads = Session::get('agent_selling_uploaded_$type'.'s', []);
$new_uploads = [];
$posted_files = Input::file('uploaded_'.$type.'s');
foreach($posted_files as $posted_file){
$path = '/uploads/tmp/'.uniqid().'.'.Userimage::guessExtension($posted_file->path());
File::copy($posted_file->path(), public_path().$path);
$posted_file_id = uniqid();
$new_uploads[$posted_file_id] = [
'id' => $posted_file_id,
'album_id' => $album_id,
'type' => $type,
'path' => $path,
];
}
Session::put('agent_selling_uploaded_$type'.'s', array_merge($existing_uploads, $new_uploads));
return response()->json([
'success' => true,
'uploads' => $new_uploads,
]);
}
同样,仅当上传“大”文件时,问题才会发生。如果文件很小,一切正常。它似乎是关于
upload_max_filesize
的问题,但我正确设置了配置文件 最佳答案
终于发现,我的操作系统上有多个php版本,其中一个(正在运行)有upload_max_filesize = 2M
和post_max_size = 8M
导致了问题