Last active
November 27, 2017 10:07
-
-
Save saraclima/5460189a7a3ff66c05bf7a6c87e214ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Uploader fichier</h1> | |
<form action="upload.php" method="post" enctype="multipart/form-data"> | |
<input type="file" name="fichiers[]" multiple="multiple" /> <br> | |
<input type="submit" value="Envoyer le fichier" /> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if(isset($_POST['delete'])){ | |
unlink("files/".$_POST['image']); | |
} | |
?> | |
<?php | |
if(!empty($_FILES['fichiers']['name'][0])) | |
{ | |
$fichiers = $_FILES['fichiers']; | |
$uploaded = array(); | |
$failed = array(); | |
$ext_allowed = array('png', 'jpg', 'gif' ); | |
foreach($fichiers['name'] as $position => $file_name){ | |
$file_size = $fichiers['size'][$position]; | |
$file_tmp = $fichiers['tmp_name'][$position]; | |
$file_extension = explode('.', $file_name); | |
$file_extension = strtolower(end($file_extension)); | |
if(in_array($file_extension, $ext_allowed)){ | |
if($file_size <= 1048576) { | |
$file_name_new = uniqid('', true).'.'.$file_extension; | |
$target_dir = 'files/'; | |
$file_destination = 'files/'.$file_name_new; | |
if(move_uploaded_file($file_tmp, $file_destination)){ | |
$uploaded[$position] = $file_destination; | |
echo 'Upload effectué avec succès !'; | |
} else{ | |
echo = "ERROR UPLOADING"; | |
} | |
}else { | |
echo "Taille trop grande"; | |
} | |
} else { | |
echo "Format pas bon"; | |
} | |
} | |
} | |
$target_dir = 'files/'; | |
$files = array_diff(scandir($target_dir),array('..', '.')); | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<TITLE>Uploaded Fichier</TITLE> | |
<meta charset="UTF-8"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"> | |
</haed> | |
</head> | |
<body> | |
<?php | |
include 'index.php'; | |
echo '<br><br>'; | |
if (isset($files)) { | |
if(is_array($files)){ | |
foreach ($files as $file){ | |
echo'<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3"> | |
<div class="thumbnail"> | |
<img src='.'files/'.$file.' > | |
<div class="caption"> | |
<h3>'.$file.'</h3> | |
<form action="" method="post" role="form"> | |
<input type="hidden" name="image" value='.$file.' > | |
<input type="submit" class="btn-danger" name="delete" value="delete"> | |
</form> | |
</div> | |
</div> | |
</div>'; | |
} | |
} | |
} | |
?> | |
</tbody> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment