Last Update : 2023-09-22 UTC 11:44:16 AM
If you mean the public folder that is not in w3coded php x the STORAGE folder, but, if you want to handle w3coded php x this with Laravel Storage (Laravel Filesystem), w3coded php x You can define this folder as a Disk for w3coded php x filesystem and use it as follow.,Edit: The w3coded php x documentation is confusing. It seems, you would w3coded php x need to use the File Facade instead. I will w3coded php x investigate a bit more, but it seems to be w3coded php x working now. ,Note : If you changed Public w3coded php x folder you can use base_path() in the Disk w3coded php x definition with relative Path as follow w3coded php x (Otherwise don't use it):, w3coded php x By clicking “Accept all cookies”, you w3coded php x agree Stack Exchange can store cookies on your w3coded php x device and disclose information in accordance w3coded php x with our Cookie Policy.
You could do this in one line:
use File;
$files = File::files(public_path());
// If you would like to retrieve a list of
// all files within a given directory including all sub-directories
$files = File::allFiles(public_path());
Solved! I've used this function and it's work :
// GET PUBLIC FOLDER FILES (NAME)
if ($handle = opendir(public_path('img'))) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
echo $entry."<br>"; // NAME OF THE FILE
}
}
closedir($handle);
}
In the filesystem config config/filesystems.php
, disks
part add this code:
'disks' => [
...
'public_site' => [
'driver' => 'local',
'root' => public_path(''),
'visibility' => 'public',
],
...
],
And then you can use this commands in your app:
$contents = Storage::get('img/file.jpg');
or to get list of files:
$files = Storage::files('img');
$files = Storage::allFiles('img');
Note : If you changed Public folder you can use base_path() in the Disk definition with relative Path as follow (Otherwise don't use it):
'disks' => [
...
'public_site' => [
'driver' => 'local',
'root' => base_path('../../public'),
'visibility' => 'public',
],
...
],
Solution 1 for Laravel
public function index()
{
$path = public_path('test');
$files = File::allFiles($path);
dd($files);
}
Solution 2 for Laravel
public function index()
{
$path = public_path('test');
$files = File::files($path);
dd($files);
}
Solution for PHP
public function index()
{
$path = public_path('demo');
$files = scandir($path);
dd($files);
}
Last Update : 2023-09-22 UTC 13:37:03 PM
Last Update : 2023-09-22 UTC 13:36:50 PM
Last Update : 2023-09-22 UTC 13:36:32 PM
Last Update : 2023-09-22 UTC 13:36:24 PM
Last Update : 2023-09-22 UTC 13:36:08 PM
Last Update : 2023-09-22 UTC 13:35:37 PM
Last Update : 2023-09-22 UTC 13:35:19 PM