1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| <?php
$compte = "demo";
$docpar = "document";
$dossierfiles = '/home/public_html/'.$compte.'/'.$docpar.'/';
$target = $dossierfiles;
$weeds = array('.','..','.htaccess','.htpasswd');
$directories = array_diff(scandir($target), $weeds);
?>
<b>/<?php echo $docpar; ?>/ : </b><br>
<form method="POST"enctype="multipart/form-data">
<?php
foreach($directories as $value)
{
if(is_file($target.$value))
{
echo ' <input style="margin-top:2px;" type="checkbox" name="file[]" value="'.$value.'" /><a style="background-color:black;color:white;text-decoration:none;font-family:Verdana;font-size:0.6em;" href="/'.$docpar.'/'.$value.'">*'.$value.'*</a> | ';
}
}
?>
<br><br>
<input type="hidden" name="MAX_FILE_SIZE" value="99000000">
Fichier : <input type="file" name="monfichier">
<button type="submit" name="submit">Update</button>
</form>
<?php
// upload
if(isset($_POST['submit']))
{
if(!empty($_FILES['monfichier']))
{
$dossier = $dossierfiles;
$fichier = basename($_FILES['monfichier']['name']);
$taille_maxi = 99000000;
$taille = filesize($_FILES['monfichier']['tmp_name']);
$extensions = array('.png', '.gif', '.jpg', '.jpeg', '.rar', 'zip');
$extension = strrchr($_FILES['monfichier']['name'], '.');
if(!in_array($extension, $extensions))
{
if(!isset($_POST['file']))
$erreur = 'Fichier acceptés: <b>.png .gif .jpg .jpeg. .rar .zip</b>';
}
if($taille>$taille_maxi)
{
$erreur = 'Le fichier est trop gros...';
}
if(!isset($erreur))
{
$fichier = strtr($fichier,
'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ',
'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
$fichier = preg_replace('/([^.a-z0-9]+)/i', '-', $fichier);
if(move_uploaded_file($_FILES['monfichier']['tmp_name'], $dossier . $fichier))
{
echo '<p>Upload effectué avec <b>succès</b> <a href="'.$_SERVER['PHP_SELF'].'">RELOAD</a> !</p>';
}
else
{
if(!isset($_POST['file']))
echo '<p><b>Echec</b> de l\'upload !</p>';
}
}
else
{
echo '<p>'.$erreur.'</p>';
}
}
// suppression
foreach($_POST['file'] as $file) {
$dirinfile = $dossierfiles.$file;
if(isset($dirinfile)) {
if (unlink($dirinfile)) {
echo 'Fichier supprimé avec succès: <b>'.$file.'</b> <a href="'.$_SERVER['PHP_SELF'].'">RELOAD</a> <br />';
} else {
echo "Fichier non supprimé: <b>$file</b><br />";
}
}
}
}
?>
<p>ATTENTION:<br><b>Pour supprimer cocher ou choisir un fichier pour uploader.</b><p>
<p><a href="../">Retour au /</a></p> |
Partager