文档
文件上传示例
<?php namespace App\Http\Controllers; use App\Http\Controllers\Controller; use Illuminate\Http\Request; use Illuminate\Support\Facades\Config; class FileController extends Controller { /** * 文件上传 * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function uploadFile(Request $request) { $path = $request->file('file')->store('upload'); return [ 'url' => Config::get('app.url') . '/' . $path, ]; } }
上传的文件会存储在目录下 storage/app/upload
修改文件配置 config/filesystems.php
return [ 'links' => [ // public_path('storage') => storage_path('app/public'), // 配置软链:public/upload -> storage/app/upload public_path('upload') => storage_path('app/upload'), ], ];
生成软链
php artisan storage:link