Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

save image in public folder instead storage laravel 5

Tags:

i wanna save my avatar at "Public" folder and ther retrieve.

ok. i can save it but in "storage/app" folder instead "public"

my friend told me go to "config/filesystem.php" and edit it ,so i did it like this

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

still no change.

here my simple codes

Route :

Route::get('pic',function (){ return view('pic.pic'); }); Route::post('saved','test2Controller@save'); 

Controller

public function save(Request $request) {         $file = $request->file('image');         //save format         $format = $request->image->extension();         //save full adress of image         $patch = $request->image->store('images');          $name = $file->getClientOriginalName();          //save on table         DB::table('pictbl')->insert([             'orginal_name'=>$name,             'format'=>$base,             'patch'=>$patch         ]);          return response()                ->view('pic.pic',compact("patch")); } 

View:

{!! Form::open(['url'=>'saved','method'=>'post','files'=>true]) !!}                 {!! Form::file('image') !!}                 {!! Form::submit('save') !!}             {!! Form::close() !!}                  <img src="storage/app/{{$patch}}"> 

How Can save my image (and file in future) at public folder instead storage?

like image 423
siros Avatar asked Mar 02 '17 17:03

siros


2 Answers

In config/filesystems.php, you could do this... change the root element in public

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

and you can access it by

Storage::disk('public')->put('filename', $file_content); 
like image 161
Ankit24007 Avatar answered Sep 30 '22 04:09

Ankit24007


You can pass disk option to method of \Illuminate\Http\UploadedFile class:

$file = request()->file('image'); $file->store('toPath', ['disk' => 'public']); 

or you can create new Filesystem disk and you can save it to that disk.

You can create a new storage disc in config/filesystems.php:

'my_files' => [     'driver' => 'local',     'root'   => public_path() . '/myfiles', ], 

in controller:

$file = request()->file('image'); $file->store('toPath', ['disk' => 'my_files']); 
like image 37
Inoyatulloh Avatar answered Sep 30 '22 04:09

Inoyatulloh