Last active
February 18, 2018 09:59
-
-
Save bazooka07/7c39e4536e194dba8a54f3e9db33fb3b to your computer and use it in GitHub Desktop.
Exemple de page statique pour PluXml : affiche liste de fichiers à télécharger
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
<div class="scrollable-table"> | |
<table class="download full-width"> | |
<thead> | |
<th> </th> | |
<th>Name</th> | |
<th>Date</th> | |
<th>Size</th> | |
<th>Description</th> | |
</thead> | |
<tbody> | |
<?php | |
$dir = 'download/'; | |
function byteConvert($bytes) { | |
if ($bytes == 0) { return "0.00 "; } | |
$s = array(' ', 'K', 'M', 'G', 'T', 'P'); | |
$e = floor(log($bytes, 1024)); | |
return round($bytes/pow(1024, $e), 2).$s[$e]; | |
} | |
# Récupération et affichage de la liste des fichiers sous forme de liste | |
global $plxMotor; | |
$root = PLX_ROOT.$plxMotor->aConf['medias'].$dir; | |
$filename = $root.'.htaccess'; | |
$descriptions = array(); | |
if(file_exists($filename)) { | |
if(preg_match_all('@^AddDescription\s+"([^"]+)"\s+(.+)$@m', file_get_contents($filename), $matches, PREG_SET_ORDER)) { | |
foreach($matches as $capture) { | |
$descriptions[$capture[2]] = $capture[1]; | |
} | |
} | |
} | |
$glob = plxGlob::getInstance($root); | |
if ($files = $glob->query('/[\w-]+\.\w+$/')) { | |
sort($files); | |
foreach($files as $filename) { | |
$href = $plxMotor->urlRewrite('?download/'.plxEncrypt::encryptId($dir.$filename)); | |
$ext = pathinfo($filename, PATHINFO_EXTENSION); | |
$time = date('Y-m-d H:i', filemtime($root.$filename)); | |
$icon = ' '; | |
$size = byteConvert(filesize($root.$filename)); | |
$description = (array_key_exists($filename, $descriptions)) ? $descriptions[$filename] : ''; | |
echo <<< TR | |
<tr> | |
<td class="$ext">$icon</td><td><a href="$href">$filename</a></td><td>$time</td><td>$size</td><td>$description</td> | |
</tr>\n | |
TR; | |
} | |
} | |
else { | |
?> | |
<tr colspan="5"><td>Aucun document</td></tr> | |
<?php | |
} | |
?> | |
</tbody> | |
</table> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment