Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save javedLive/2d31a42c7940f9b6ca2bdc263b4bfe44 to your computer and use it in GitHub Desktop.
Save javedLive/2d31a42c7940f9b6ca2bdc263b4bfe44 to your computer and use it in GitHub Desktop.
Image Upload Laravel On Storage folder
Upload Controller Code:
public function postDownload(Request $request)
{
$download = new Download();
$download->name = $request->Input(['name']);
if($request->hasFile('display_image'))
{
$file = Input::file('display_image');
$filePath = time().str_random(10).'.'.$request->display_image->getClientOriginalExtension();
$download->display_image = $filePath;
Storage::disk('theme_image')->put($filePath, \File::get($file));
}
if($request->hasFile('file_path'))
{
$file = Input::file('file_path');
$filePath = time().str_random(10).'.'.$request->file_path->getClientOriginalExtension();
$download->file_path = $filePath;
Storage::disk('files')->put($filePath, \File::get($file));
}
foreach( array('product_thumbnail','cover_image','detail_image') as $type)
{
if( $request->file($type) )
{
$filename = time().str_random(10). '.' . $request->file($type)->getClientOriginalExtension();
$download->$type = $filename;
Storage::disk('theme_image')->put($filename, \File::get($request->file( $type )));
}
}
$download->save();
return redirect('get-download');
}
For File Download Controller :
public function downloadFile(Request $request)
{
$download = DB::table('downloads')->where('id',$request->id)->select('file_path')->first();
return response()->download(storage_path("app/theme_file/{$download->file_path}"));
}
Filesystem.php
'files' => [
'driver' => 'local',
'root' => storage_path('app/theme_file'),
],
'theme_image' => [
'driver' => 'local',
'root' => storage_path('app/public/theme_picture'),
],
Create public folder with following Command:
php artisan storage:link
Access from View:
"{{asset('storage/theme_image/'.$row->product_thumbnail)}}"
If Main project outside public_html put this in the \App\Providers\AppServiceProvider register() method.
public function register()
{
// ...
$this->app->bind('path.public', function() {
return base_path('public_html');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment