1. Go to this page and download the library: Download beriyack/storage library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
beriyack / storage example snippets
yack\Storage;
eriyack\Storage;
// --- Exemples de gestion de fichiers ---
$filePath = 'my_document.txt';
$directoryPath = 'my_data_folder';
// 1. Écrire du contenu dans un fichier (crée ou écrase)
Storage::put($filePath, "Salut le monde!\nCeci est un test.");
echo "Fichier créé ou mis à jour : " . $filePath . "\n";
// 2. Lire le contenu d'un fichier
$content = Storage::get($filePath);
if ($content !== false) {
echo "Contenu de '" . $filePath . "' :\n" . $content . "\n";
}
// 3. Prépendre du contenu
Storage::prepend($filePath, "--- Début du fichier ---\n");
echo "Contenu après prépend : \n" . Storage::get($filePath) . "\n";
// 4. Appendre du contenu
Storage::append($filePath, "\n--- Fin du fichier ---\n");
echo "Contenu après append : \n" . Storage::get($filePath) . "\n";
// 5. Vérifier si un fichier existe
if (Storage::exists($filePath)) {
echo "'" . $filePath . "' existe.\n";
}
if (Storage::isFile($filePath)) {
echo "'" . $filePath . "' est un fichier.\n";
}
// 6. Obtenir des informations sur le fichier
echo "Taille de '" . $filePath . "' : " . Storage::size($filePath) . " octets\n";
echo "Dernière modification de '" . $filePath . "' : " . date('Y-m-d H:i:s', Storage::lastModified($filePath)) . "\n";
echo "Type MIME de '" . $filePath . "' : " . (Storage::mimeType($filePath) ?: 'Inconnu') . "\n";
echo "Extension de '" . $filePath . "' : " . Storage::extension($filePath) . "\n";
echo "Nom de '" . $filePath . "' (sans extension) : " . Storage::name($filePath) . "\n";
// --- Exemples de gestion de répertoires ---
// 1. Créer un répertoire
if (Storage::makeDirectory($directoryPath)) {
echo "Répertoire créé : " . $directoryPath . "\n";
}
// 2. Vérifier si un chemin est un répertoire
if (Storage::isDirectory($directoryPath)) {
echo "'" . $directoryPath . "' est un répertoire.\n";
}
// 3. Lister les fichiers et répertoires directs
file_put_contents($directoryPath . DIRECTORY_SEPARATOR . 'file_in_dir.txt', 'Contenu');
Storage::makeDirectory($directoryPath . DIRECTORY_SEPARATOR . 'sub_dir');
echo "\nFichiers dans '" . $directoryPath . "' : \n";
print_r(Storage::files($directoryPath));
echo "\nRépertoires dans '" . $directoryPath . "' : \n";
print_r(Storage::directories($directoryPath));
// 4. Lister tous les fichiers/répertoires (récursif)
echo "\nTous les fichiers (récursif) :\n";
print_r(Storage::allFiles('.')); // Scanne le répertoire courant
echo "\nTous les répertoires (récursif) :\n";
print_r(Storage::allDirectories('.')); // Scanne le répertoire courant
// 5. Déplacer un fichier
$newFilePath = 'temp_folder' . DIRECTORY_SEPARATOR . 'moved_document.txt';
if (Storage::move($filePath, $newFilePath)) {
echo "Fichier déplacé vers : " . $newFilePath . "\n";
$filePath = $newFilePath; // Mettre à jour le chemin pour les opérations futures
}
// --- Nettoyage ---
// Nettoyer un répertoire (supprime le contenu, pas le répertoire lui-même)
// if (Storage::cleanDirectory($directoryPath)) {
// echo "\nRépertoire '" . $directoryPath . "' vidé.\n";
// }
// Supprimer un fichier
if (Storage::exists($filePath)) {
unlink($filePath); // Utiliser unlink pour les fichiers
echo "Fichier '" . $filePath . "' supprimé.\n";
}
// Supprimer un répertoire et son contenu
if (Storage::deleteDirectory($directoryPath)) {
echo "Répertoire '" . $directoryPath . "' et son contenu supprimés.\n";
}
// Supprimer le dossier temporaire créé par le déplacement
if (Storage::deleteDirectory('temp_folder')) {
echo "Répertoire 'temp_folder' supprimé.\n";
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.