Laravel - plugin to view existing folders and files in Storage->app->public

Asked

Viewed 100 times

0

need a help, someone knows some plugin to show real-time the existing folders and files in Storage>>app>>>public in Laravel?

I found this plugin that does what I want: Demo: https://demo.tutorialzine.com/2014/09/cute-file-browser-jquery-ajax-php/

But I can’t convert the file scan php. to a code understandable by Laravel 5.4

The PHP code of the Scan file:

<?php

$dir = "files";

// Run the recursive function 

$response = scan($dir);


// This function scans the files folder recursively, and builds a large array

function scan($dir){

	$files = array();

	// Is there actually such a folder/file?

	if(file_exists($dir)){
	
		foreach(scandir($dir) as $f) {
		
			if(!$f || $f[0] == '.') {
				continue; // Ignore hidden files
			}

			if(is_dir($dir . '/' . $f)) {

				// The path is a folder

				$files[] = array(
					"name" => $f,
					"type" => "folder",
					"path" => $dir . '/' . $f,
					"items" => scan($dir . '/' . $f) // Recursively get the contents of the folder
				);
			}
			
			else {

				// It is a file

				$files[] = array(
					"name" => $f,
					"type" => "file",
					"path" => $dir . '/' . $f,
					"size" => filesize($dir . '/' . $f) // Gets the size of this file
				);
			}
		}
	
	}

	return $files;
}



// Output the directory listing as JSON

header('Content-type: application/json');

echo json_encode(array(
	"name" => "files",
	"type" => "folder",
	"path" => $dir,
	"items" => $response
));

  • Where is your scan.php file?

  • Ademilson can download the package at this link https://tutorialzine.com/2014/09/cute-file-browser-jquery-ajax-php

  • Why do you say the code is not understandable by Laravel 5.4? It’s just a function, I think I can put it inside a class (which you should create) and call it the point of the code you want, it wouldn’t be that?

  • I tried to use more not showed the selected directory

  • But the code is simple, just see if you were looking at the correct directory. Have you tried to display a print in the directory you were trying to list? Or have you seen if you have this permission in the p/ folder? Needs to go debugging point by point, however the code I guarantee is valid for Laravel 5.4 (otherwise you would have screen errors)...

  • My problem is to implement the function in the respective controller in Laravel, especially the header('Content-type: application/json');

  • Have you read the missing part about HTTP Responses in the Laravel 5.4 doc? https://laravel.com/docs/5.4/responses There explains how to return with this type of header...

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.