Aide

Fichiers de la Commune

Ajouter un fichier

Choisir un fichier à téléverser
5 Mo) !"); // check if file type is allowed (optional) $allowedFileTypes = array( "application/vnd.oasis.opendocument.spreadsheet", "application/vnd.oasis.opendocument.text", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/msword", "image/jpg", "image/jpeg", "application/pdf", "text/plain" // , "image/png", "image/gif", "image/jpg", "image/jpeg", "image/pjpeg" ); if (!in_array($_FILES['data']['type'], $allowedFileTypes)) { my_die("ERREUR: '".$file['basename']."',type de fichier non accepté."); } // check if this is a valid upload if (!is_uploaded_file($_FILES['data']['tmp_name'])) { my_die("ERREUR: Le téléversement a échoué"); } // set the name of the target directory move_uploaded_file($_FILES['data']['tmp_name'], $relPath.$_FILES['data']['name']) or my_die("Impossible de copier le fichier"); echo '- Fichier '.$_FILES['data']['name'].' correctement enregistré : Continuer...'; } // Liste des fichiers echo "

Liste des fichiers

"; //IF THE sort FLAG HASN'T BEEN SET YET, SET THE DEFAULT $dirList = getFileList($relPath); if(!isset($_GET['triPar'])) { $_GET['triPar'] = 'nom'; } switch($_GET['triPar']) { case 'taille' : $sortres = usort($dirList, 'compsize'); break; case 'nom' : $sortres = usort($dirList, 'compname'); break; case 'date' : $sortres = usort($dirList, 'compdate'); break; } $sortOnName = 'Nom'; $sortOnDate = 'Date de mise en ligne'; $sortOnSize = 'Taille'; // output file list in HTML TABLE format echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; foreach($dirList as $file) { echo "\n"; echo "\n"; if ($file['size'] > 999999) $fsize = number_format($file['size']/1000000, 1, ',', ' ')." Mo"; elseif ($file['size'] > 999) $fsize = number_format($file['size']/1000, 1, ',', ' ')." ko"; else $fsize = $file['size']." octets"; echo "\n"; echo "\n"; echo ''; echo "\n"; } echo "\n"; echo "
$sortOnName$sortOnSize$sortOnDate
{$file['basename']}$fsize",utf8_encode(strftime('%A %d %B %Y %H:%M', $file['lastmod'])),"
\n\n"; function getFileList($dir) { // array to hold return value $retval = array(); // add trailing slash if missing if(substr($dir, -1) != "/") $dir .= "/"; // open pointer to directory and read list of files $d = @dir($dir) or my_die("ERREUR: répertoire inaccessible, contacter l'administrateur."); while(false !== ($entry = $d->read())) { // skip hidden files if($entry[0] == ".") continue; if(is_dir("$dir$entry")) { $retval[] = array( "name" => "$dir$entry", "basename" => basename("$dir$entry"), "type" => filetype("$dir$entry"), "size" => 0, "lastmod" => filemtime("$dir$entry") ); } elseif(is_readable("$dir$entry")) { $retval[] = array( "name" => "$dir$entry", "basename" => basename("$dir$entry"), "type" => mime_content_type("$dir$entry"), "size" => filesize("$dir$entry"), "lastmod" => filemtime("$dir$entry") ); } } $d->close(); return $retval; } function compname($filea, $fileb) { return(strcmp(mb_strtoupper($filea['basename']), mb_strtoupper($fileb['basename']))); } function compsize($filea, $fileb) { return($filea['size'] > $fileb['size'] ? 0 : 1); } function compdate($filea, $fileb) { return($filea['lastmod'] > $fileb['lastmod'] ? 0 : 1); } function my_die($message) { die($message . ' Retour...'); } function SupprimeAccentsEtBlancs($str, $encoding='utf-8') { $str = str_replace(" ", "_", $str); $str = str_replace("'", "_", $str); // transformer les caractères accentués en entités HTML $str = htmlentities($str, ENT_NOQUOTES, $encoding); $str = preg_replace('#&([A-za-z])(?:acute|grave|cedil|circ|orn|ring|slash|th|tilde|uml);#', '\1', $str); // Remplacer les ligatures tel que : Œ, Æ ... // Exemple "œ" => "oe" $str = preg_replace('#&([A-za-z]{2})(?:lig);#', '\1', $str); // Supprimer tout le reste $str = preg_replace('#&[^;]+;#', '', $str); return $str; } function TrashPath($fullFilePath) { global $relTrashPath; $trashList = getFileList($relTrashPath); $count = 1; $pathParts = pathinfo($fullFilePath); $newFullFilePath = $relTrashPath . $pathParts['basename']; while(FileExists($trashList, $newFullFilePath)) { $tempFileName = sprintf("%s (%d)", $pathParts['filename'], $count++); $newFullFilePath = $relTrashPath . $tempFileName; } return $newFullFilePath; } function FileExists($trashList, $fullFilePath) { foreach ($trashList as $file) { if ($fullFilePath == $file['name']) return true; } return false; } ?>