【发布时间】:2018-03-28 01:55:03
【问题描述】:
我正在使用 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有关,但我正确设置了配置文件
【问题讨论】:
标签: javascript php jquery laravel file-upload