Neeraj1005's avatar

Image store in your custom base_path

Getting Error while store image outside the storage directory.

Could not move the file "C:\Users\Nick\AppData\Local\Temp\phpEFF2.tmp" to "/uploads/leads25825402.jpg" ().

this is my image upload code

use WithFileUploads;
public $fileUpload

public function storeData() {
$validatedData = $this->validate([
            'first_name' => 'required|max:255',
            'last_name' => 'required|max:255',
            'email' => 'required|email|max:255',
            'fileUpload' => 'nullable|image',
            'company' => 'nullable|exists:companies,id'
        ]) + ['uid' => auth()->user()->id];

        if ($this->fileUpload) {
            $filename = time() . '.' . $this->fileUpload->getClientOriginalExtension();
            // $this->fileUpload->storeAs('uploads/leads/', $filename);
            $path = $this->fileUpload->move('/uploads/leads', $filename);

            $validatedData['fileUpload'] = '/uploads/leads/' . $filename;
        }
}
0 likes
1 reply
Neeraj1005's avatar
Neeraj1005
OP
Best Answer
Level 9

Now I solved this problem using adding my custom disk in filesystems.php

   'disks' => [
		
        'customUploads' => [
            'driver' => 'local',
            'root' => base_path('uploads'),
            'url' => env('APP_URL').'/uploads',
            'visibility' => 'public',
        ],

    ],

Then in controller

   $validatedData = $this->validate([
            'first_name' => 'required|max:255',
            'last_name' => 'required|max:255',
            'email' => 'required|email|max:255',
            'fileUpload' => 'nullable|image',
            'company' => 'nullable|exists:companies,id'
        ]) + ['uid' => auth()->user()->id];

        if ($this->fileUpload) {
            $filename = time() . '.' . $this->fileUpload->getClientOriginalExtension();
            
			$this->fileUpload->storeAs('leads', $filename, 'customUploads');

            $validatedData['fileUpload'] = '/uploads/leads/' . $filename;
        }

Please or to participate in this conversation.