Your IP : 216.73.216.59


Current Path : /home/quelfutuu/www/lchg/
Upload File :
Current File : /home/quelfutuu/www/lchg/archivage_MP.php

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head>
<meta charset="utf-8" />
<title>la Commune - Fichiers</title>
<link rel="stylesheet" href="lchgstyle.css" type="text/css" />
<script type="text/javascript" src="lchgscript.js" /></script>
</head>
<body>
<div class="page">
<div id="form_supprime"></div>
<div id="form_renomme"></div>
<p class="right"><b><a href="aide.html">Aide</a></b></p>
<h2>Fichiers de <b><i>la Commune</i></b></h2>
<h4>Ajouter un fichier</h4>
<?php
	setlocale(LC_TIME, 'fr_FR');
	$relPath = "depot/";
	$relTrashPath = "trash/";

	if (isset($_POST['fichier_a_supprimer'])) {
		$oldFullFilePath = $relPath . $_POST['fichier_a_supprimer'];
		$newFullFilePath = TrashPath($oldFullFilePath);
//		echo "old: " . $oldFullFilePath . ", new: $newFullFilePath";
//		$trashList = getFileList($relTrashPath);
		rename($oldFullFilePath, $newFullFilePath);
	}

	if (isset($_POST['fichier_a_renommer']) && isset($_POST['nouveau_nom'])) {
		$newFullFilePath = $relPath . SupprimeAccentsEtBlancs($_POST['nouveau_nom']);
		$oldFullFilePath = $relPath . $_POST['fichier_a_renommer'];
		rename($oldFullFilePath, $newFullFilePath);
	}

	//  display  file  upload  form
	if  (!isset($_POST['submit']))  { ?>
		<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
		<input type="hidden" name="MAX_FILE_SIZE" value="5000000" /> Choisir un fichier &agrave; t&eacute;l&eacute;verser
		<input type="file" name="data"/><br />
		<input type="submit" name="submit" value="T&eacute;l&eacute;verser le fichier" />
		</form>
	<?php
	} 
	else  {
		foreach($_FILES as &$file) $file['name'] = SupprimeAccentsEtBlancs($file['name']);
		unset($file);
		// check for existing file
		$dirList = getFileList($relPath);
		foreach($dirList as $file) {
			if ($_FILES['data']['name'] == $file['basename']) my_die("\nERREUR: le fichier '".$file['basename']."' est d&eacute;j&agrave; pr&eacute;sent !"); 
		}
		//  check  uploaded  file  size
		if  ($_FILES['data']['size']  ==  0) my_die("\nERREUR: Absence de fichier, fichier vide ou fichier trop gros (> 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&eacute;.");
		} //  check  if  this  is  a  valid  upload	
		if  (!is_uploaded_file($_FILES['data']['tmp_name']))   {
			my_die("ERREUR: Le t&eacute;l&eacute;versement a &eacute;chou&eacute;");
		} //  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 <i>'.$_FILES['data']['name'].'</i> correctement enregistr&eacute; : <b><a href="'.$_SERVER['PHP_SELF'].'">Continuer...</a></b>';
 	}
// Liste des fichiers
	echo "<h4>Liste des fichiers</h4>";
	//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 = '<a href="' . $_SERVER['PHP_SELF'] . '?triPar=nom">Nom</a>';
	$sortOnDate = '<a href="' . $_SERVER['PHP_SELF'] . '?triPar=date">Date de mise en ligne</a>';
	$sortOnSize = '<a href="' . $_SERVER['PHP_SELF'] . '?triPar=taille">Taille</a>';
// output file list in HTML TABLE format
	echo "<table border=\"1\">\n";
	echo "<thead>\n";
	echo "<tr><th>$sortOnName</th><th>$sortOnSize</th><th>$sortOnDate</th></tr>\n";
		echo "</thead>\n";
		echo "<tbody>\n";
		foreach($dirList as $file) {
			echo "<tr>\n";
			echo "<td><a href=\"$relPath{$file['basename']}\" type=\"{$file['type']}\">{$file['basename']}</a></td>\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 "<td class=\"right\">$fsize</td>\n";
			echo "<td>",utf8_encode(strftime('%A %d %B %Y %H:%M', $file['lastmod'])),"</td>\n";
			echo '<td> <div class="dropdown"> <button onclick="menudisplay(\'', $file['basename'], '\')" class="dropbtn">Modifier</button>';
			echo '<div id="Menu-', $file['basename'], '" class="dropdown-content"> <a href="" onclick="renomme(\'', $file['basename'], '\', event)">Renommer</a>';
			echo '<a href="" onclick="supprime(\'', $file['basename'], '\', event)">Supprimer</a> </div>';
			echo '</div></td>'; 
			echo "</tr>\n";
		}
		echo "</tbody>\n";
		echo "</table>\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&eacute;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 . ' <b><a href="' . $_SERVER['PHP_SELF'] . '">Retour...</a></b>');
	}
	
	function SupprimeAccentsEtBlancs($str, $encoding='utf-8') {
		$str = str_replace(" ", "_", $str);
		$str = str_replace("'", "_", $str);
		// transformer les caract&egrave;res accentu&eacute;s en entit&eacute;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 : Œ, &AElig; ...
		// Exemple "&oelig;" => "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;
	}
?>

</div>
</body>
</html>