Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $thelist = '';
- $count = 0;
- $filelist = array();
- if ($handle = opendir('./storage')) {
- while (false !== ($file = readdir($handle))) {
- if ($file != "." && $file != "..") {
- $filelist[] = $file;
- $count = $count+1;
- }
- }
- closedir($handle);
- }
- /*var_dump($filelist);*/
- function human_filesize($bytes, $decimals = 2) {
- $size = array('B','kB','MB','GB','TB','PB','EB','ZB','YB');
- $factor = floor((strlen($bytes) - 1) / 3);
- return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$size[$factor];
- }
- function findexts ($filename) {
- $filename=strtolower($filename);
- $exts= pathinfo($filename, PATHINFO_EXTENSION);
- return $exts;
- }
- for($index=0; $index<$count; $index++){
- $name = pathinfo($filelist[$index], PATHINFO_FILENAME);
- $namehref = $filelist[$index];
- $extn = findexts($filelist[$index]);
- $size = human_filesize(filesize('./storage/'.$filelist[$index]));
- $thelist .= '<li><span class="type">'.$extn.'</span><span class="link"><a href=./storage/'.$namehref.'>'.$name.'</a></span><span class="size">'.$size.'</span><span class="fa fa-trash-o fa-fw" aria-hidden="true"></span>
- </li>';
- }
- if($count > 0){
- echo json_encode(array('heading' => '<div id="found">Here is all!</div>', 'list' => $thelist));
- }
- else{
- echo json_encode(array('heading' => '<div id="empty_storage"><img src="icon.png"><br>Its lonely here!</div>', 'list' => $thelist));
- }
- ?>
Add Comment
Please, Sign In to add comment