Please use the following code and get all the subdirectories of a specific folder in the shared folder. When someone clicks on a folder, the files inside each folder are displayed in it.
Controller file
public function index() { try { $dirNames = array(); $this->folderPath = 'export'.DS.str_replace( '.', '_', $this->getCurrentShop->getCurrentShop()->shopify_domain ).DS.'exported_files'; $getAllDirs = File::directories( public_path( $this->folderPath ) ); foreach( $getAllDirs as $dir ) { $dirNames[] = basename($dir); } return view('backups/listfolders', compact('dirNames')); } catch ( Exception $ex ) { Log::error( $ex->getMessage() ); } } public function getFiles( $directoryName ) { try { $filesArr = array(); $this->folderPath = 'export'.DS.str_replace( '.', '_', $this->getCurrentShop->getCurrentShop()->shopify_domain ).DS.'exported_files'. DS . $directoryName; $folderPth = public_path( $this->folderPath ); $files = File::allFiles( $folderPth ); $replaceDocPath = str_replace( public_path(),'',$this->folderPath ); foreach( $files as $file ) { $filesArr[] = array( 'fileName' => $file->getRelativePathname(), 'fileUrl' => url($replaceDocPath.DS.$file->getRelativePathname()) ); } return view('backups/listfiles', compact('filesArr')); } catch (Exception $ex) { Log::error( $ex->getMessage() ); } }
Route (Web.php)
Route::resource('displaybackups', 'Displaybackups\BackupController')->only([ 'index', 'show']);
Route :: get ('get-files / {directoryName}', 'Displaybackups \ BackupController @getFiles');
Browse Files - List Folders
@foreach( $dirNames as $dirName) <div class="col-lg-3 col-md-3 col-sm-4 align-center"> <a href="get-files/{{$dirName}}" class="btn btn-light folder-wrap" role="button"> <span class="glyphicon glyphicon-folder-open folderIcons"></span> {{ $dirName }} </a> </div> @endforeach
View - file list
@foreach( $filesArr as $fileArr) <div class="col-lg-2 col-md-3 col-sm-4"> <a href="{{ $fileArr['fileUrl'] }}" class="waves-effect waves-light btn green folder-wrap"> <span class="glyphicon glyphicon-file folderIcons"></span> <span class="file-name">{{ $fileArr['fileName'] }}</span> </a> </div> @endforeach
Liz eipe c
source share