-
Notifications
You must be signed in to change notification settings - Fork 4
/
getfiles.php
51 lines (42 loc) · 1.43 KB
/
getfiles.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);
ob_start();
require __DIR__ . '/vendor/autoload.php';
if (!isset($_COOKIE['t2s'])) {
echo json_encode([
'message' => 'Aucun fichier récent'
]);
}
$root = __DIR__ . '/audio/';
$directory = htmlspecialchars($_COOKIE['t2s']);
$user_dir = $root . $directory;
$relative_user_dir = '/audio/' . $directory . '/';
if (file_exists($user_dir)) {
$iterator = new RecursiveDirectoryIterator($user_dir);
$files = [];
$files['files'] = [];
$files['relative_user_dir'] = $relative_user_dir;
// Loop through files
foreach(new RecursiveIteratorIterator($iterator) as $file) {
if ($file->isFile() && ($file->getExtension() == 'mp3' || $file->getExtension() == 'zip')) {
$files['files'][] = [
'name' => $file->getFilename(),
'date' => date("d/m/Y H:i", filemtime($file->getPathname())),
'id' => $file->getBasename('.'.$file->getExtension()),
'type' => $file->getExtension()
];
}
}
usort($files['files'], function( $a, $b ) {
return strtotime($b["date"]) - strtotime($a["date"]);
});
echo json_encode($files);
}
else {
echo json_encode(
[
'message' => 'Le dossier utilisateur n\'existe pas encore'
]);
}