0

Hi I am using Blue shared Hosting and I've been trying surfing around this site looking for answers, but nothing works for me, I want to upload an image that save in public_html folder, instead of saving it in project folder (I separate the project folder and put all public file in public_html folder). but it returns to my project folder, not public_html one. please help me how can resolve that thanks.

Controller

if($request->has('image')){
            $imageName = Storage::disk('cms')->putFile('', $request->image);
            $home_slider->image  =   $imageName;
            $home_slider->save();
        }

filesystem.php

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

2 Answers 2

1

Perhaps you can try changing:

$imageName = Storage::disk('cms')->putFile('', $request->image);

To:

$imageName = Storage::disk('local')->putFile('uploads', $request->image);

Assuming that the folder you want to upload your image to under public_html is named uploads

Sign up to request clarification or add additional context in comments.

Comments

0

I assume that you have one folder named uploads under public_html

If you don't want any custom image name . Just store file as it is. you can do like:-

          $imagename = $request->txtFile->store('uploads');  
          $imagename=str_replace('uploads/','',$imagename);
          $destinationPath = 'uploads';
          $file->move($destinationPath, $imagename);

If you want to give custom name, then you can do like this:-

for eg:

          $random = Str::random(10);
          $timestamp=strtotime(date('H:i:s')).$random;
          $customfilename=$slug.'-logo-'.$timestamp.'.'.$fileextension;
          $imagename = $request->txtFile->storeAs('uploads',$customfilename);  
          $imagename=str_replace('uploads/','',$imagename);
          $destinationPath = 'uploads';
          $file->move($destinationPath, $imagename);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.