Laravelで500MB近くのファイルを扱う必要があり、ファイルアップロード機能を作成したのですが、300MBを超えるファイルをアップロードしようとすると、Requestから「The file failed to upload.」のエラーを返されてしまいアップロードができません。まず、どこに原因があるのか調査するのもままならないレベルです。
該当のコード
fileup.blade.php
php
1<form method="post" action="{{ action('FileupsController@store') }}" enctype="multipart/form-data"> 2 {{ csrf_field() }} 3 <input type="file" name="file"> 4 @if ($errors->has('file')) 5 {{ $errors->first('file') }} //ここでThe file failed to upload. 6 @endif 7 <input type="submit" value="アップロード"> 8</form>
FileRequest.php
php
1namespace App\Http\Requests; 2 3use Illuminate\Foundation\Http\FormRequest; 4 5class FileRequest extends FormRequest 6{ 7 8 public function authorize(){ 9 return true; 10 } 11 12 public function rules(){ 13 $rules = array( 14 'file' => 'required|mimes:jpg,jpeg,png,gif,pdf,mp4,MP4,vtt,txt' 15 ); 16 return $rules; 17 } 18}
FileController.php
php
1<?php 2namespace App\Http\Controllers; 3 4use Illuminate\Http\Request; 5use Illuminate\Support\Facades\Auth; 6use App\Http\Requests\FileRequest; 7use Storage; 8 9class MediasController extends Controller 10{ 11 public function store(MediaRequest $request, $is_modal = false) { 12 $file = $request->file('file'); 13 $extension = $file->extension(); 14 $filename = date('YmdHis').'.'.$extension; 15 $flag = $request->file->storeAs('public/',$filename); 16 // アップロード失敗 17 if(!$flag) { 18 // ファイルの削除 19 Storage::disk('local')->delete('public/'.$filename); 20 return back()->with('flash_message', 'Media Failed!')->withInput(); 21 } 22 return back()->with('flash_message', '最高にかっこいい'); 23 } 24}
試したこと
ファイルサイズの問題から、php.iniをそれぞれめちゃあげました
memory_limit = 1G
post_max_size = 2G
upload_max_filesize = 2G
.htaccessではファイルのアップロードに関する指定はしておりません。
よろしくお願いします。
filesystems.php
PHP
1<?php 2 3return [ 4 5 /* 6 |-------------------------------------------------------------------------- 7 | Default Filesystem Disk 8 |-------------------------------------------------------------------------- 9 | 10 | Here you may specify the default filesystem disk that should be used 11 | by the framework. The "local" disk, as well as a variety of cloud 12 | based disks are available to your application. Just store away! 13 | 14 */ 15 16 'default' => 'local', 17 18 /* 19 |-------------------------------------------------------------------------- 20 | Default Cloud Filesystem Disk 21 |-------------------------------------------------------------------------- 22 | 23 | Many applications store files both locally and in the cloud. For this 24 | reason, you may specify a default "cloud" driver here. This driver 25 | will be bound as the Cloud disk implementation in the container. 26 | 27 */ 28 29 'cloud' => 's3', 30 31 /* 32 |-------------------------------------------------------------------------- 33 | Filesystem Disks 34 |-------------------------------------------------------------------------- 35 | 36 | Here you may configure as many filesystem "disks" as you wish, and you 37 | may even configure multiple disks of the same driver. Defaults have 38 | been setup for each driver as an example of the required options. 39 | 40 | Supported Drivers: "local", "ftp", "s3", "rackspace" 41 | 42 */ 43 44 'disks' => [ 45 46 'local' => [ 47 'driver' => 'local', 48 'root' => storage_path('app'), 49 ], 50 51 'public' => [ 52 'driver' => 'local', 53 'root' => storage_path('app/public'), 54 'visibility' => 'public', 55 ], 56 57 's3' => [ 58 'driver' => 's3', 59 'key' => 'your-key', 60 'secret' => 'your-secret', 61 'region' => 'your-region', 62 'bucket' => 'your-bucket', 63 ], 64 65 ], 66 67];


回答3件
あなたの回答
tips
プレビュー