Created
September 10, 2019 08:51
-
-
Save amin007/4f14dad66705114160c73166d0cec789 to your computer and use it in GitHub Desktop.
papar fail / list files in php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
#------------------------------------------------------------------------------------------------------------- | |
/* | |
$fileList = glob('/*.*'); | |
foreach($fileList as $filename) | |
{ | |
# Use the is_file function to make sure that it is not a directory. | |
if(is_file($filename)) | |
{ | |
echo $filename . '<br>'; | |
} | |
} | |
*/ | |
#------------------------------------------------------------------------------------------------------------- | |
function getFileList($dir) | |
{ | |
# array to hold return value | |
$retval = []; | |
# add trailing slash if missing | |
if(substr($dir, -1) != "/") { $dir .= "/"; } | |
# open pointer to directory and read list of files | |
$d = @dir($dir) or die("getFileList: Failed opening directory {$dir} for reading"); | |
while(FALSE !== ($entry = $d->read())) | |
{ | |
# skip hidden files | |
if($entry{0} == ".") continue; | |
if(is_dir("{$dir}{$entry}")) | |
{ | |
$retval[] = [ | |
'name' => "{$dir}{$entry}/", | |
'type' => filetype("{$dir}{$entry}"), | |
'size' => 0, | |
'lastmod' => filemtime("{$dir}{$entry}") | |
]; | |
} | |
elseif(is_readable("{$dir}{$entry}")) | |
{ | |
$retval[] = [ | |
'name' => "{$dir}{$entry}", | |
'type' => mime_content_type("{$dir}{$entry}"), | |
'size' => filesize("{$dir}{$entry}"), | |
'lastmod' => filemtime("{$dir}{$entry}") | |
]; | |
} | |
} | |
$d->close(); | |
return $retval; | |
} | |
#------------------------------------------------------------------------------------------------------------- | |
function pautan($name,$web) | |
{ | |
$icon1 = '<i class="fas fa-globe-asia fa-spin"></i>'; | |
$icon2 = '<i class="far fa-folder fa-spin"></i>'; | |
$icon = ($name != $web) ? $icon1 : $icon2; | |
return '' . $icon | |
. '<a target="_blank" href="' . $web . '">' | |
. $name . '</a><hr>'; | |
} | |
#------------------------------------------------------------------------------------------------------------- | |
function list_files() | |
{ | |
$dirlist = getFileList("./"); | |
//echo "<pre>",print_r($dirlist),"</pre>"; | |
//echo '<tr><td> name</td><td> type</td><td> size</td><td> lastmod</td></tr>'; | |
$failIni = basename($_SERVER['PHP_SELF']); | |
diatas(); | |
echo "\n$failIni<hr>"; | |
foreach(getWebsite() as $name => $web): | |
echo "\n" . pautan($name,$web); | |
endforeach; | |
foreach($dirlist as $key02 => $value): | |
if ($value['type'] == 'dir'): | |
echo "\n" . pautan($value['name'],$value['name']); | |
else:echo '';endif; | |
endforeach; | |
dibawah(); | |
} | |
#------------------------------------------------------------------------------------------------------------- | |
function getWebsite() | |
{ | |
$papar = array( | |
'./espl/'=>'//espl.stats.gov.my/spl', | |
'./mailstats/'=>'//mail.stats.gov.my', | |
'./newss/'=>'//newss.stats.gov.my', | |
'./msic/'=>'//msic.stats.gov.my', | |
'./emasco/'=>'https://www.jobsmalaysia.gov.my/emasco', | |
'./eBGB/'=>'https://ebgb.dosm.gov.my', | |
'./qss/'=>'https://qss.stats.gov.my/qssv3', | |
'./ejob/'=>'https://ejob.stats.gov.my', | |
'./ideps/'=>'https://ideps.dosm.gov.my', | |
'./kalendar/'=>'https://www.mysumber.com/cuti-umum.html' | |
); | |
return $papar; | |
} | |
#------------------------------------------------------------------------------------------------------------- | |
function diatas() | |
{ | |
print <<<END | |
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> | |
<meta name="description" content=""> | |
<meta name="author" content=""> | |
<title>List Folder</title> | |
<link href="https://use.fontawesome.com/releases/v5.4.2/css/all.css" rel="stylesheet" type="text/css"> | |
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" type="text/css"> | |
<style type="text/css"> | |
table.excel { | |
border-style:ridge; | |
border-width:1; | |
border-collapse:collapse; | |
font-family:sans-serif; | |
font-size:11px; | |
} | |
table.excel thead th, table.excel tbody th { | |
background:#CCCCCC; | |
border-style:ridge; | |
border-width:1; | |
text-align: center; | |
vertical-align: top; | |
} | |
table.excel tbody th { text-align:center; vertical-align: top; } | |
table.excel tbody td { vertical-align:bottom; } | |
table.excel tbody td | |
{ | |
padding: 0 3px; border: 1px solid #aaaaaa; | |
background:#ffffff; | |
} | |
</style> | |
</head> | |
<body> | |
END; | |
} | |
#------------------------------------------------------------------------------------------------------------- | |
function dibawah() | |
{ | |
print <<<END | |
<!-- Footer | |
================================================== --> | |
<!-- footer class="footer"> | |
<div class="container"> | |
<span class="label label-info"> | |
© Hak Cipta Terperihara 2019. Theme Asal Bootstrap Twitter | |
</span> | |
</div> | |
</footer --> | |
<!-- khas untuk jquery dan js2 lain | |
================================================== --> | |
<script type="text/javascript" src="https://code.jquery.com/jquery-2.2.3.min.js"></script> | |
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script> | |
</body> | |
</html> | |
END; | |
} | |
#------------------------------------------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment