Skip to content

Instantly share code, notes, and snippets.

@mustafat0k
Created February 8, 2018 02:59
Show Gist options
  • Save mustafat0k/f39d27f40f4a4c249418f8e239a8b604 to your computer and use it in GitHub Desktop.
Save mustafat0k/f39d27f40f4a4c249418f8e239a8b604 to your computer and use it in GitHub Desktop.
Laravel file ovveride
<?php
public function get_dir(Request $request)
{
$root = base_path() . DIRECTORY_SEPARATOR;
// "C:\Users\fizikci\Desktop\dev\la1\"
$postDir = rawurldecode(base_path($request->get('dir')));
if (file_exists($postDir))
{
$files = scandir($postDir);
// dd($files);
$returnDir = substr($postDir, strlen($root));
natcasesort($files);
if (count($files) > 2)
{ // The 2 accounts for . and ..
echo "<ul class='jqueryFileTree'>";
foreach ($files as $file)
{
$htmlRel = htmlentities($returnDir . $file);
$htmlName = htmlentities($file);
$ext = preg_replace('/^.*\./', '', $file);
if (file_exists($postDir . $file) && $file != '.' && $file != '..')
{
if (is_dir($postDir . $file))
{
echo "<li class='directory collapsed'><a rel='" . $htmlRel . "/'>" . $htmlName . "</a></li>";
}
else
{
echo "<li class='file ext_{$ext}'><a rel='" . $htmlRel . "'>" . $htmlName . "</a></li>";
}
}
}
echo "</ul>";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment