Livewire tmp/phpLznimY 不存在

问题描述 投票:0回答:1

当我尝试选择要上传的图像时,会出现此错误。

Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException
The file "/tmp/phpLznimY" does not exist

是否要预览图像并不重要。我检查了

storage/app/livewire-tmp
目录,文件正在上传到该目录中。它将在本地计算机上运行,但不能在生产服务器上运行。

"laravel/framework": "^8.0",
"livewire/livewire": "^2.10",

我检查了 livewire 配置和文件系统配置文件,这些看起来不错。

'temporary_file_upload' => [
        'disk' => 'local',        // Example: 'local', 's3'              Default: 'default'
        'rules' => null,       // Example: ['file', 'mimes:png,jpg']  Default: ['required', 'file', 'max:12288'] (12MB)
        'directory' => 'livewire-tmp',   // Example: 'tmp'                      Default  'livewire-tmp'
        'middleware' => null,  // Example: 'throttle:5,1'             Default: 'throttle:60,1'
        'preview_mimes' => [   // Supported file types for temporary pre-signed file URLs.
            'png', 'gif', 'bmp', 'svg', 'wav', 'mp4',
            'mov', 'avi', 'wmv', 'mp3', 'm4a',
            'jpg', 'jpeg', 'mpga', 'webp', 'wma',
        ],
        'max_upload_time' => 5, // Max duration (in minutes) before an upload gets invalidated.
    ],

文件系统

'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

我已经尝试过本地和公共,但相同的错误仍然不断出现。 upload_max_filesize 是 2GB,所以这应该不是问题。

<form wire:submit.prevent="saveCustomer" enctype="multipart/form-data">
...........
<div class="form-group row">
  <div class="col-sm-1"></div>
  <label class="col-sm-3 col-form-label" for="logo">Logo:</label>
  <div class="col-sm-3">
    <input wire:model="logo" type="file" name="logo" class="form-control-file btn btn-primary"/>
    @error('logo') <span class="text-danger mt-1">{{ $message }}</span> @enderror
  </div>
  <div class="col-sm-2">
    @if($logo)<img src="{{ $logo->temporaryUrl() }}">@endif
  </div>
</div>
............
</form>

这是徽标的验证

'logo' => 'nullable|image|mimes:png,png,jpeg,gif|max:10000000',

而且我还没有将其上传到服务器。首先我想看预览。但正如我所说,tmp 文件正在上传到 livewire-tmp 文件夹中。当我检查文件夹时,我看到它正在上传到该文件夹。

但不知怎的,它似乎想要从 tmp 文件夹中获取文件。而且文件名 (

"/tmp/phpLznimY"
) 与实际名称并不接近。

php laravel laravel-livewire image-upload
1个回答
0
投票

我之前做的时候也遇到过这个问题。

对我来说,问题是我将变量 (wire:model) 设置为

string
类型。我不知道它会破坏上传文件功能。

// Not working
public string $logo;

// Working
public $logo;

我希望这对和我有同样情况的人有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.