Skip to content

Instantly share code, notes, and snippets.

@bazooka07
Last active February 18, 2018 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bazooka07/7c39e4536e194dba8a54f3e9db33fb3b to your computer and use it in GitHub Desktop.
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
<div class="scrollable-table">
<table class="download full-width">
<thead>
<th>&nbsp;</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&nbsp;"; }
$s = array('&nbsp;', '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 = '&nbsp;';
$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