You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel 5.6 文件上传异常:文件未存入storage/app目录

Troubleshooting File Not Appearing in 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 logos directory 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-data for 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:35:20