Laravel 5.6 文件上传异常:文件未存入storage/app目录
storage/app It’s frustrating when the filename is returned successfully but the file doesn’t show up in your storage/app directory—let’s walk through the most common fixes for this Laravel issue:
1. Check Directory Permissions & Existence
First, ensure the target directory exists and has write permissions for your web server:
- Create the
logosdirectory if it doesn’t exist:mkdir -p storage/app/logos - Set proper permissions (adjust the user/group to match your server setup, e.g.,
www-datafor Apache/Nginx):chmod -R 755 storage chown -R www-data:www-data storage
Laravel should create directories automatically, but permission restrictions often block this behavior.
2. Explicitly Specify the Filesystem Disk
While local is the default storage disk, explicitly defining it in your storeAs call can rule out configuration mismatches:
Update your controller code to:
public function letterOfIntent(Request $request) { $fileName = "fileName".time().'.'.$request->fileToUpload->getClientOriginalExtension(); // Add 'local' as the third parameter to enforce storage in storage/app $request->fileToUpload->storeAs('logos', $fileName, 'local'); return 'success'; }
The local disk is configured to point to storage/app by default in config/filesystems.php.
3. Add Validation to Catch Silent Upload Errors
You’re currently not validating the file upload, which means you might be getting silent failures (like oversized files) but still returning "success". Add validation to your method:
public function letterOfIntent(Request $request) { // Validate the file matches your view's requirements $validated = $request->validate([ 'fileToUpload' => 'required|file|max:2048', // Max 2MB as noted in your view // Add mimes rules if needed, e.g., 'mimes:pdf,jpg,jpeg,png' ]); $fileName = "fileName".time().'.'.$request->fileToUpload->getClientOriginalExtension(); $request->fileToUpload->storeAs('logos', $fileName, 'local'); return 'success'; }
This will throw an error response if the file fails validation, so you’ll know exactly why the upload isn’t working.
4. Debug the Exact Storage Path
Add logging to confirm where Laravel is attempting to store the file:
public function letterOfIntent(Request $request) { if ($request->hasFile('fileToUpload') && $request->file('fileToUpload')->isValid()) { $fileName = "fileName".time().'.'.$request->fileToUpload->getClientOriginalExtension(); $path = $request->fileToUpload->storeAs('logos', $fileName, 'local'); // Log the full absolute path to your Laravel logs (storage/logs/laravel.log) \Log::info('File stored at: ' . storage_path('app/' . $path)); return 'success'; } return 'Upload failed: No valid file provided'; }
Check your logs to see the exact path Laravel is using—this will tell you if the file is being stored somewhere unexpected.
5. Clean Up Redundant Form Attribute
Quick note on your view: you have method="post" twice in the form tag. Remove one to clean up your code:
<form method="post" action="/supplier-information/company-officer/letter-of-intent" enctype="multipart/form-data" data-form-method="create">
内容的提问来源于stack exchange,提问作者Martney Acha

