Code :
<?
function head() {
echo '
<html>
<head>
<style type="text/css">
.folder, .file {
font-family:verdana;
font-size: 11px;
}
.folder {
color:orange;
}
.elements {
padding-left:20px;
}
.file, a {
color:black;
}
</style>
<script language="JavaScript">
function open_img(url, x, y) {
x = parseInt(x)+parseInt(20);
y = parseInt(y)+parseInt(20);
window.open(url, "aproposde", "toolbar=no, location=no, directories=no,
status=no, scrollbars=no, resizable=no, copyhistory=no, width="+x+", height="+y+", left=300, top=50");
}
</script>
</head>
<body><table width="100%"><tr><td width="30%"><form name="apply"
method="post" enctype="multipart/form-data">';
}
function foot() {
echo '</td><td width="70%"><span class="file">
S?lectionnez les images sur lesquelles ?crire<br>puis ?crivez le copyright ? ins?rer: </span><br>'
.'<input type="text" name="copyright" maxlength="30" style="height:20px;width:200px;
vertical-align:middle"> '
.'<input type="submit" value="Ecrire" name="Ecrire" style="height:22px;
font-size: 11px;vertical-align:middle;"><br><br>'
.'<select name="couleur" style="height:18px;vertical-align:middle;font-size:11px">'
.'<option value="red">Rouge</option><option value="black">Noir</option>
<option value="white">Blanc</option></select> <span class="file">couleur du copyright</span><br>'
.'<input type="checkbox" name="suppr" style="vertical-align:middle">
<span class="file">Supprimer les fichiers sources</span>'
.'<br><br><br><span class="file">Pour supprimer les fichiers s?lectionn?s, cliquez ici:</span>
<input type="submit" value="Supprimer" name="Ecrire" style="height:22px;font-size: 11px;vertical-align:middle;">'
.'</form></td></tr></table>'
.'</body></html>';
}
function explore($homedir, $start='1') {
$extension = array('gif', 'jpeg', 'bmp', 'png');
$output = '';
if ($start == 1)
$output .= '<span class="file">Contenu du dossier</span> <span class="folder">'.$homedir.'/</span><br>';
$dir = openDir($homedir);
while ($file = readDir($dir)) {
if (($file!=".")&&($file!="..")) {
if (is_dir("$homedir/$file")) {
$output .= '<div class="folder">+ '.$file.'/</div>';
$subelements = explore("$homedir/$file", 0);
if ($subelements !== '') {
$output .= '<div class="elements">'.$subelements.'</div>';
}
} else {
list($width, $height, $type) = @getimagesize("images/".$file);
if ($type == 1) $type = 'gif';
elseif ($type == 2) $type = 'jpeg';
elseif ($type == 3) $type = 'png';
elseif ($type == 6) $type = 'bmp';
if (in_array($type, $extension)) {
$output .= "<div class=\"file\"><input type='checkbox' value='".$type."' name='delete[".$file."]'
style='vertical-align:middle'> "
."<a href=\"#\" title=\"Voir l'image\" OnClick=\"open_img('images/".$file."', '".$width."', '".$height."')\">".$file."</a></div>";
}
}
}
}
closeDir($dir);
return $output;
}
function submit() {
if ($_POST['Ecrire'] == 'Supprimer') {
if (isset($_POST['delete'])) {
foreach($_POST['delete'] As $image => $type) {
unlink('images/'.$image);
}
}
}
else {
if (isset($_POST['copyright']) && !empty($_POST['copyright'])) $copyright = trim($_POST['copyright']); else $copyright = '';
if (!empty($copyright)) {
$delete = (isset($_POST['suppr']) && $_POST['suppr'] == 'on') ? 'ok' : 'no';
if (isset($_POST['delete'])) {
foreach($_POST['delete'] As $image => $type) {
$fonction = 'imagecreatefrom'.$type;
$im = $fonction('images/'.$image);
switch($_POST['couleur']) {
case 'red':
$textcolor = imagecolorallocate($im, 255, 0, 0);
break;
case 'black':
$textcolor = imagecolorallocate($im, 0, 0, 0);
break;
case 'white':
$textcolor = imagecolorallocate($im, 255, 255, 255);
break;
default: $textcolor = imagecolorallocate($im, 0, 0, 0);
}
list($width_p, $height_p, $type_p) = getimagesize("images/".$image);
$pos_y = $height_p -2;
$font = 'arial.ttf';
$taille = 13;
while (($taille-2)*(strlen(stripslashes($copyright))) > $width_p) {
$taille--;
if ($taille == 5) break;
}
imagettftext($im, $taille, 0, 5, $pos_y, $textcolor, $font, stripslashes($copyright));
$renvoi = 'image'.$type;
if ($type == 'jpeg') $type_file = 'jpg'; else $type_file = $type;
if (isset($_POST['suppr']) && $_POST['suppr'] == 'on') unlink('images/'.$image);
$renvoi($im, 'images/'.substr($image, 0, -4).'-done.'.$type_file);
imagedestroy($im);
}
}
}
}
}
if (isset($_POST['Ecrire'])) submit();
head();
echo explore("images");
foot();
?>