Reputation: 167
I wanted to check the files inside my public path 'public/img/certs' but it returns an array. Im currently using laravel 5.5 and my first time using the 'Storage' file system.
use Illuminate\Support\Facades\Storage;
public function index(Request $request)
{
$path = base_path() . '/public/img/certs';
$files = Storage::files($path);
dd($files);
return view('dashboard.index');
}
Upvotes: 2
Views: 218
Reputation: 577
Try below code in your controller hope this will help you to store the file in storage location of your application.
if($request->hasFile('image')){
$image_name=$request->image->getClientOriginalName();
$request->image->storeAs('public',$image_name);
}
$request->user()->profile_pic=$request->image;
$request->user()->save();
return back();
Modified it according to your requirement so this code work definately.
Upvotes: 0
Reputation: 2673
try this code, reference link
$files = File::allFiles($directory);
foreach ($files as $file)
{
echo (string)$file, "\n";
}
Upvotes: 2
Reputation: 179994
First, $files = Storage::files('$path');
won't work at all, because the variable won't be interpreted.
Second, Storage::files
will return an array because you asked for files and gave it a directory. The array will contain all the files in that directory.
Third, consider the public_path
helper for this:
$path = public_path('img/certs');
It's a bit cleaner and will work if you ever put your public files somewhere non-standard.
Upvotes: 0