https://openclassrooms.com/forum/sujet/filesize-naffiche-pas-la-taille
Last active
November 19, 2019 15:43
-
-
Save julp/6dcbaec4d337cf64160e3e0005b18e83 to your computer and use it in GitHub Desktop.
[OC]
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 | |
const ROOT = 'adresse du répertoire'; | |
$videos = iterator_to_array( | |
new RegexIterator( | |
new FilesystemIterator(ROOT, FilesystemIterator::CURRENT_AS_PATHNAME), | |
'#\.(mov|avi|mp4)$#i' | |
) | |
); | |
if (!$videos) { | |
echo 'Aucun document mis en ligne ...'; | |
} else { | |
rsort($videos); | |
echo <<<'EOH' | |
<table> | |
<tr> | |
<td>Date</td> | |
<td>Aperçu</td> | |
<td>Fichiers vidéos</td> | |
<td>Taille</td> | |
</tr> | |
EOH; | |
foreach ($videos as $video) { | |
$image = preg_replace('~\.avi$~i', '.jpg', $video); | |
list($nom, $dateang) = explode('-', pathinfo($video, PATHINFO_FILENAME), 2); | |
$datefr = implode('/', array_reverse(preg_split('~[.]~', $nom))); | |
$size = filesize($video); | |
echo <<<EOH | |
<tr> | |
<td>{$datefr}</td> | |
<td><img src="{$image}" /></td> | |
<td><a href="{$video}" target="_blank">{$nom}</a></td> | |
<td>{$size}</td> | |
</tr> | |
EOH; | |
} | |
echo '</table>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment