Skip to content

Instantly share code, notes, and snippets.

@cortomalese
Last active September 28, 2015 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cortomalese/942989 to your computer and use it in GitHub Desktop.
Save cortomalese/942989 to your computer and use it in GitHub Desktop.
Ce script affiche récursivement les sous-dossiers et les fichiers. Il extrait les miniatures EXIF des images qui en possèdents.
<!--script explorer.php-->
// Voici les coordonnées du script d'origine
// http://forum.phpfrance.com/php-debutant/aide-sur-une-navigation-dans-une-arborescence-t30844.html
// que j'ai partiellement modifié
<head>
<script LANGUAGE="JavaScript">
parametres="toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,width=1024,height=768,left=150,top=50";
function OuvrirFenetre(lien) {
f=window.open(lien,"fenetre",parametres);
f.focus();
}
</script></head>
<?
// url du script exécuté
$self=$PHP_SELF;
// dirname() extrait le chemin de l'url
$chemin=safe_dirname($self);
// getcwd() donne le chemin réel sur le système de fichier hôte
$rep=getcwd();
// pour récupérer les valeurs des paramètres éventuellement transmis par formulaire
if (isset($_POST['rep'])) {
$rep=$_POST['rep'];
$chemin=$_POST['ch'];
}
echo "<h4>$chemin</h4>";
$compt=0;
// $rep doit être un chemin de rép. réel sur le système : ne pas l'afficher
if( $dir = opendir($rep) ) {
while( FALSE !== ($fich = readdir($dir)) ) {
/* $fich est toujours un nom sans chemin d'accès !
* il désigne un fichier ou un s-rép ou les pseudo-rép '.' ou '..'
*/
// pour bloquer la remontée au dessus de la racine du site web
if (($fich == "..") && ($chemin !="/") ){
// $rep contient le chemin réel vers le rép. courant
chdir($rep);
// pour se déplacer au rép. parent
chdir("..");
// pour récupérer ainsi le nouveau chemin
$newrep=getcwd();
// calculer le nouveau chemin WEB en éliminant le dernier rép.
if (preg_match("#^\S+/\S+$#",$chemin) )
$newchemin=preg_replace("#(\S+)/\S+$#", "$1",$chemin);
else
$newchemin= "/";
// transmission de $rep et $chemin par champs cachés de formulaire
echo "<form action='$self' method='post' >
<input type='hidden' name='rep' value='$newrep'>
<input type='hidden' name='ch' value='$newchemin'>
</form>";
// activer le lien provoque le rechargement du script
echo "<a href='#' onclick='document.forms[0].submit();'>
<img src='../images/style_dotdot.jpg' width=20 height=20 border=0 ><b>..</b></a>
<br>";
}
elseif ($fich != ".") {
if (is_dir("$rep/$fich")) {
// pour compter les formulaires associés
$compt++;
chdir("$rep/$fich");
$newrep=getcwd();
$newchemin= "$chemin/$fich";
echo "<form action='$self' method='post' >
<input type='hidden' name='rep' value='$newrep'>
<input type='hidden' name='ch' value='$newchemin'>
</form>";
echo "<a href='#' onclick='document.forms[$compt].submit();'>
<img src='../images/style_directory.jpg' width=20 height=20 border=0>$compt-$fich</a>
<br>";
}
else
{
$url = "./$chemin/$fich";
echo "<a href=\"javascript: OuvrirFenetre('$url');\">";
$ext = strtolower(substr($fich,strlen($fich)-3)); //get the extension of an image
if ($ext == "jpg") {
$image = exif_thumbnail($url, $width, $height, $type);
echo "<img width='$width' height='$height' src='data:image/gif;base64,".base64_encode($image)."'><br>$fich</a></n>";
}
else
{
echo "<img src='../images/style_file.jpg' width=20 height=20 border=0>$fich</a><br>";
}
}
}
}
}
?>
<?php
function safe_dirname($path)
{
$dirname = dirname($path);
return $dirname == '/' ? '' : $dirname;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment