[英]empty input while uploading file with FormData in laravel
我正在使用 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
導致了問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.