Skip to content

Instantly share code, notes, and snippets.

@Florencelg Florencelg/index.php
Created Oct 23, 2018

What would you like to do?
Quête php: laisse pas traîner ton File
<! Doctype html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Multiple File Upload</title>
$authorisedExtension = ['png', 'gif', 'jpg'];
$maxSize = 1048576;
if(count($_FILES['upload']['name']) > 0){
//Loop through each file
for($i=0; $i<count($_FILES['upload']['name']); $i++) {
$extension = pathinfo($_FILES['upload']['name'][$i], PATHINFO_EXTENSION);
if (in_array($extension, $authorisedExtension)) {
if($_FILES['upload']['size'][$i] < $maxSize){
//Get the temp file path
$tmpFilePath = $_FILES['upload']['tmp_name'][$i];
//Make sure we have a filepath
if($tmpFilePath != ""){
//save the filename
$shortname = $_FILES['upload']['name'][$i];
//save the url and the file
$filePath = "uploaded/" .'image'.uniqid(). ".".$extension;
//Upload the file into the temp dir
if(move_uploaded_file($tmpFilePath, $filePath)) {
$files[] = $shortname;
//insert into db
//use $shortname for the filename
//use $filePath for the relative url to the file
echo "le fichier est trop lourd";
echo "mauvais type de fichier";
//show success message
echo "<h1>Uploaded:</h1>";
echo "<ul>";
foreach($files as $file){
echo "<li>$file</li>";
echo "</ul>";
$it = new FilesystemIterator('uploaded/');
foreach ($it as $fileinfo) {?>
<form method="post" action="index.php">
<img src="../uploaded/<?php echo $fileinfo->getFilename() ?>" alt="..." class="img-thumbnail"> <br />
<button type="submit" value="<?php echo $fileinfo->getFilename() ?>" name="delete">Delete</button>
echo $fileinfo->getFilename() . "\n";
} ?>
if (isset($_POST['delete'])){
if(file_exists ( $filePath)){
<h1>Laisse pas traîner ton File</h1>
<form action="" enctype="multipart/form-data" method="post">
<label for='upload'>Add Attachments:</label>
<input id='upload' name="upload[]" type="file" multiple="multiple"/>
<p><input type="submit" name="submit" value="Submit"></p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.