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
| <form method="POST" action="" enctype="multipart/form-data">
<div class="form-div">
<label for="file" class="input-label">
<i class="fas fa-download"></i>
<span id="label_span" name="test">Selectionner un fichier</span>
</label>
<input id="file" type="file" name="userfile">
<button type="submit" class="btn btn-green" name="upload">Envoyer</button>
</div>
</form>
<?php
if(isset($_FILES['userfile'])) {
$userfile = $_FILES['userfile']['name'];
$phpFileUploadErrors = array(
0 => "<div style='color: green'>Le fichier à bien été envoyé</div>",
1 => 'Le fichier est trop gros (ne doit pas dépasser 20mo)',
2 => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form',
3 => 'The uploaded file was only partially uploaded',
4 => "<div style='color: red'>Veuillez sélectionner une fichier</div>",
6 => 'Missing a temporary folder',
7 => 'Failed to write file to disk.',
8 => 'A PHP extension stopped the file upload.',
);
if(!empty($_FILES['userfile']['error'])) {
echo $phpFileUploadErrors[$_FILES['userfile']['error']];
} else {
echo "<div style='color: green'>Le fichier à bien été envoyé</div>";
$bdd = new PDO("mysql:host=localhost;dbname=amandineBDD", "root", "");
$req = $bdd->prepare("INSERT INTO img (item_nom, item_date) VALUES ('$userfile', NOW())");
$req->execute(array($userfile));
fopen(getcwd() . "/upload/" . $userfile, "w");
}
}
$req = $bdd->query("SELECT id, item_nom, DATE_FORMAT(item_date, '%d/%m/%Y') AS item_date FROM img");
$items = $req->fetchAll();
?>
<br>
<table class="table-fill">
<thead>
<tr>
<th class="text-left">Nom</th>
<th class="text-left">Ajouté le</th>
<th class="text-left">Actions</th>
</tr>
</thead>
<tbody class="table-hover">
<?php foreach ($items as $item) { ?>
<tr>
<td><?= $item['item_nom']; ?><a style='margin-left: 15px;' class='lien-pdf' target='_blank' href='upload/<?= $item['item_nom'] ?>'><button class='btn btn-close'>Télécharger</button></a></td>
<td><?= $item['item_date']; ?></td>
<td><i class='fal fa-edit' data-modal='modalUpdateItem'></i> <a href="delete.php?id=<?= $item['id']; ?>"><i class='fal fa-trash-alt'></i></a></td>
</tr>
<?php } ?>
</tbody>
</table> |
Partager