webfuelcode's avatar

Image does not upload on server but good on localhost

filesystems.php

    'disks' => [

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

        'public' => [
            'driver' => 'local',
            'root' => public_path('img'),
            'url' => env('APP_URL').'/img',
            'visibility' => 'public',
        ],

        's3' => [
            'driver' => 's3',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_BUCKET'),
            'url' => env('AWS_URL'),
        ],

    ],

Controller to create category with image

public function catcreate(Request $request, Category $cat)
    {
        $validated = $this->validate($request,[            
            'name'=>'required|min:4',
            'image'=>'required|image'
        ]);

        if($request->hasFile('image')){
            $filename = time() . '.' . $request->image->getClientOriginalExtension();
            $request->image->storeAs('category', $filename, 'public');
            
            $validated['image'] = $filename;
        }

        //store
        $cat = Category::create($validated);

        return redirect()->route('catindex')->withMessage('Category created successfully!');
    }
0 likes
6 replies
Snapey's avatar

nothing to link

you are trying to save directly into the public/img folder. Do you have permissions for that?

Any errors?

Is the image being stored somewhere else?

webfuelcode's avatar

@Snapey I thought I have something wrong on the coding side. But the image uploads to under public folder.

I have created a folder and uploaded all files there, then moved all files and folders from the public folder to the root. And also added the folder name in the index.php file require __DIR__.'/coopon/vendor/autoload.php';

I have noticed the image goes to ...coopon/public/category/.....[filename]...

I think I have to change public_path('img')

But what to put there...

webfuelcode's avatar

@Snapey I just wanted to know when to use public_path, base_path or others

As I am using the images to store in a custom folder (not in laravel storage). Suppose I want to store the image in www.somthing.com/img/...

So, in the filesystems.php what should be there in 'root' => .................,

Snapey's avatar

@webfuelcode your file system config is ok as long as public folder is the document root

If you can see public In your urls then it's more complicated

But, what is going wrong? Is the file uploaded into the expected folder?

Please or to participate in this conversation.