prend en compte les fichiers stockés avec les anciennes v1 & v2 du projet
This commit is contained in:
parent
b31f6fff8d
commit
0018ac8554
85
admin.php
85
admin.php
@ -289,51 +289,52 @@ $files = $fileData['files'];
|
||||
<div class="file-list">
|
||||
<?php foreach ($files as $file): ?>
|
||||
<div class="file-item">
|
||||
<div class="file-preview">
|
||||
<?php if ($file['preview_type'] === 'image'): ?>
|
||||
<img src="fichiers/<?php echo Cyla::escape($file['name']); ?>"
|
||||
alt="<?php echo Cyla::escape($file['name']); ?>">
|
||||
<?php else: ?>
|
||||
<div class="preview-placeholder">
|
||||
<?php echo strtoupper($file['extension']); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="file-info">
|
||||
<p class="file-name"><?php echo Cyla::escape($file['name']); ?></p>
|
||||
<p class="file-meta">
|
||||
<?php echo Cyla::escape(round($file['size'] / 1024, 2)); ?> Ko
|
||||
· <?php echo date('d/m/Y H:i', $file['uploaded']); ?>
|
||||
</p>
|
||||
<div class="file-actions">
|
||||
<a href="share.php?file=<?php echo urlencode($file['name']); ?>"
|
||||
class="btn btn-secondary"
|
||||
target="_blank">Voir</a>
|
||||
<button class="btn"
|
||||
onclick="copyShareLink('<?php echo SITE_URL; ?>share.php?file=<?php echo urlencode($file['name']); ?>')">
|
||||
Copier le lien
|
||||
</button>
|
||||
<button class="btn btn-danger"
|
||||
onclick="confirmDelete('<?php echo Cyla::escape($file['name']); ?>')">
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="file-preview">
|
||||
<?php if ($file['preview_type'] === 'image'): ?>
|
||||
<img src="<?php echo $file['path'] . Cyla::escape($file['name']); ?>"
|
||||
alt="<?php echo Cyla::escape($file['name']); ?>">
|
||||
<?php else: ?>
|
||||
<div class="preview-placeholder">
|
||||
<?php echo strtoupper($file['extension']); ?>
|
||||
</div>
|
||||
|
||||
<!-- Formulaire caché pour la suppression -->
|
||||
<form id="deleteForm-<?php echo Cyla::escape($file['name']); ?>"
|
||||
action="admin.php"
|
||||
method="POST"
|
||||
style="display: none;">
|
||||
<input type="hidden" name="action" value="delete_file">
|
||||
<input type="hidden" name="filename" value="<?php echo Cyla::escape($file['name']); ?>">
|
||||
<input type="hidden" name="csrf_token" value="<?php echo Cyla::generateCSRFToken(); ?>">
|
||||
</form>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="file-info">
|
||||
<p class="file-name"><?php echo Cyla::escape($file['name']); ?></p>
|
||||
<p class="file-meta">
|
||||
<?php echo Cyla::escape(round($file['size'] / 1024, 2)); ?> Ko
|
||||
· <?php echo date('d/m/Y H:i', $file['uploaded']); ?>
|
||||
· <?php echo $file['path']; ?>
|
||||
</p>
|
||||
<div class="file-actions">
|
||||
<a href="share.php?file=<?php echo urlencode($file['name']); ?>&path=<?php echo urlencode($file['path']); ?>"
|
||||
class="btn btn-secondary"
|
||||
target="_blank">Voir</a>
|
||||
<button class="btn"
|
||||
onclick="copyShareLink('<?php echo SITE_URL; ?>share.php?file=<?php echo urlencode($file['name']); ?>&path=<?php echo urlencode($file['path']); ?>')">
|
||||
Copier le lien
|
||||
</button>
|
||||
<button class="btn btn-danger"
|
||||
onclick="confirmDelete('<?php echo Cyla::escape($file['name']); ?>', '<?php echo Cyla::escape($file['path']); ?>')">
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Formulaire caché pour la suppression -->
|
||||
<form id="deleteForm-<?php echo Cyla::escape($file['name']); ?>"
|
||||
action="admin.php"
|
||||
method="POST"
|
||||
style="display: none;">
|
||||
<input type="hidden" name="action" value="delete_file">
|
||||
<input type="hidden" name="filename" value="<?php echo Cyla::escape($file['name']); ?>">
|
||||
<input type="hidden" name="path" value="<?php echo Cyla::escape($file['path']); ?>">
|
||||
<input type="hidden" name="csrf_token" value="<?php echo Cyla::generateCSRFToken(); ?>">
|
||||
</form>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php if ($fileData['totalPages'] > 1): ?>
|
||||
<div class="pagination">
|
||||
<?php if ($fileData['currentPage'] > 1): ?>
|
||||
|
@ -11,6 +11,10 @@ define('SITE_VERSION', '3.0.1');
|
||||
define('SITE_URL', 'https://concepts.esenjin.xyz/cyla/');
|
||||
|
||||
// Files configuration
|
||||
define('LEGACY_UPLOAD_DIRS', [
|
||||
__DIR__ . '/v1/img/fichiers/',
|
||||
__DIR__ . '/v2/file/'
|
||||
]);
|
||||
define('UPLOAD_DIR', __DIR__ . '/fichiers/');
|
||||
define('MAX_FILE_SIZE', 100 * 1024 * 1024); // 100 Mo en octets
|
||||
define('ALLOWED_EXTENSIONS', [
|
||||
|
69
core.php
69
core.php
@ -138,7 +138,17 @@ class Cyla {
|
||||
*/
|
||||
public static function listFiles($page = 1, $perPage = 20) {
|
||||
$files = [];
|
||||
$allFiles = glob(UPLOAD_DIR . '*');
|
||||
$allFiles = [];
|
||||
|
||||
// Ajouter les fichiers du dossier principal
|
||||
$allFiles = array_merge($allFiles, glob(UPLOAD_DIR . '*'));
|
||||
|
||||
// Ajouter les fichiers des dossiers hérités
|
||||
foreach (LEGACY_UPLOAD_DIRS as $dir) {
|
||||
if (is_dir($dir)) {
|
||||
$allFiles = array_merge($allFiles, glob($dir . '*'));
|
||||
}
|
||||
}
|
||||
|
||||
// Trier les fichiers par date de modification (plus récent en premier)
|
||||
usort($allFiles, function($a, $b) {
|
||||
@ -148,7 +158,7 @@ class Cyla {
|
||||
// Calculer la pagination
|
||||
$total = count($allFiles);
|
||||
$totalPages = ceil($total / $perPage);
|
||||
$page = max(1, min($page, $totalPages)); // Garantir que la page est dans les limites
|
||||
$page = max(1, min($page, $totalPages));
|
||||
$offset = ($page - 1) * $perPage;
|
||||
|
||||
// Récupérer uniquement les fichiers de la page courante
|
||||
@ -156,12 +166,24 @@ class Cyla {
|
||||
|
||||
foreach ($pageFiles as $file) {
|
||||
$info = pathinfo($file);
|
||||
$relativePath = '';
|
||||
|
||||
// Déterminer le chemin relatif selon le dossier
|
||||
if (strpos($file, UPLOAD_DIR) === 0) {
|
||||
$relativePath = 'fichiers/';
|
||||
} elseif (strpos($file, __DIR__ . '/v1/img/fichiers/') === 0) {
|
||||
$relativePath = 'v1/img/fichiers/';
|
||||
} elseif (strpos($file, __DIR__ . '/v2/file/') === 0) {
|
||||
$relativePath = 'v2/file/';
|
||||
}
|
||||
|
||||
$files[] = [
|
||||
'name' => basename($file),
|
||||
'size' => filesize($file),
|
||||
'extension' => strtolower($info['extension']),
|
||||
'extension' => strtolower($info['extension'] ?? ''),
|
||||
'uploaded' => filemtime($file),
|
||||
'preview_type' => getPreviewType($info['extension'])
|
||||
'preview_type' => getPreviewType($info['extension'] ?? ''),
|
||||
'path' => $relativePath // Ajout du chemin relatif
|
||||
];
|
||||
}
|
||||
|
||||
@ -173,23 +195,50 @@ class Cyla {
|
||||
'perPage' => $perPage
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Supprime un fichier
|
||||
* @param string $filename Nom du fichier à supprimer
|
||||
* @param string $path Chemin relatif du fichier
|
||||
* @return array ['success' => bool, 'error' => string|null]
|
||||
*/
|
||||
public static function deleteFile($filename) {
|
||||
$filepath = UPLOAD_DIR . $filename;
|
||||
public static function deleteFile($filename, $path = 'fichiers/') {
|
||||
// Déterminer le chemin complet selon le dossier
|
||||
$basePath = '';
|
||||
switch ($path) {
|
||||
case 'v1/img/fichiers/':
|
||||
$basePath = __DIR__ . '/v1/img/fichiers/';
|
||||
break;
|
||||
case 'v2/file/':
|
||||
$basePath = __DIR__ . '/v2/file/';
|
||||
break;
|
||||
default:
|
||||
$basePath = UPLOAD_DIR;
|
||||
}
|
||||
|
||||
// Vérifier que le fichier existe et est dans le dossier d'upload
|
||||
$filepath = $basePath . $filename;
|
||||
|
||||
// Vérifier que le fichier existe et est dans le bon dossier
|
||||
if (!file_exists($filepath) || !is_file($filepath)) {
|
||||
return ['success' => false, 'error' => 'Fichier introuvable'];
|
||||
}
|
||||
|
||||
// Vérifier que le fichier est bien dans le dossier d'upload
|
||||
// Vérifier que le fichier est bien dans un des dossiers autorisés
|
||||
$realpath = realpath($filepath);
|
||||
$uploadDir = realpath(UPLOAD_DIR);
|
||||
if (strpos($realpath, $uploadDir) !== 0) {
|
||||
$allowed = false;
|
||||
|
||||
if (strpos($realpath, realpath(UPLOAD_DIR)) === 0) {
|
||||
$allowed = true;
|
||||
} else {
|
||||
foreach (LEGACY_UPLOAD_DIRS as $dir) {
|
||||
if (strpos($realpath, realpath($dir)) === 0) {
|
||||
$allowed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$allowed) {
|
||||
return ['success' => false, 'error' => 'Chemin de fichier non autorisé'];
|
||||
}
|
||||
|
||||
|
17
share.php
17
share.php
@ -10,7 +10,22 @@ if (!isset($_GET['file'])) {
|
||||
$error = 'Aucun fichier spécifié';
|
||||
} else {
|
||||
$filename = $_GET['file'];
|
||||
$filepath = UPLOAD_DIR . $filename;
|
||||
$path = $_GET['path'] ?? 'fichiers/';
|
||||
|
||||
// Déterminer le chemin complet selon le dossier
|
||||
$basePath = '';
|
||||
switch ($path) {
|
||||
case 'v1/img/fichiers/':
|
||||
$basePath = __DIR__ . '/v1/img/fichiers/';
|
||||
break;
|
||||
case 'v2/file/':
|
||||
$basePath = __DIR__ . '/v2/file/';
|
||||
break;
|
||||
default:
|
||||
$basePath = UPLOAD_DIR;
|
||||
}
|
||||
|
||||
$filepath = $basePath . $filename;
|
||||
|
||||
// Vérifier si le fichier existe
|
||||
if (!file_exists($filepath)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user