Bonjour toujours le bug de l'affichage (rien ne s'affiche)
Voici mon code:d'affichage et de upload;
<?php
foreach($req as $r){
$info = new SplFileInfo($r['fileNameNew']);
$extaudio = array('.mp3', '.flac');
$extimage = array('png', 'jpg');
if(in_array($info, $extaudio)){
?>
<div class="card" style="width: 45rem;">
<div class="card-body" align="center">
<h6 align="left"><?= $r['author'] ?></h6>
<?php echo "<audio src='uploads/".$r['fileNameNew']."' controls>"; ?>
<h3><?= $r['content'] ?></h5>
<a href="#" class="btn btn-success">Like</a>
<a href="#" class="btn btn-danger">Dislike</a>
</div>
</div><br>
<?php
}elseif(in_array($info, $extimage)){
?>
<div class="card" style="width: 45rem;">
<div class="card-body" align="center">
<h6 align="left"><?= $r['author'] ?></h6>
<?php echo "<image src='uploads/".$r['fileNameNew']."'>"; ?>
<h3><?= $r['content'] ?></h5>
<a href="#" class="btn btn-success">Like</a>
<a href="#" class="btn btn-danger">Dislike</a>
</div>
</div><br>
<?php
}
}
?>
//upload
<?php
session_start();
include('config/connexionDB.php');
if(!empty($_POST)){
extract($_POST);
$valid = true;
// On se place sur le bon formulaire grâce au "name" de la balise "input"
if (isset($_POST['post'])){
$content = htmlentities(trim($content)); // On récupère le mot de passe
$author = $_SESSION['username'];
// Si toutes les conditions sont remplies alors on fait le traitement
if($valid){
$file = $_FILES['file'];
$fileName = $_FILES['file']['name'];
$fileTmpName = $_FILES['file']['tmp_name'];
$fileSize = $_FILES['file']['size'];
$fileError = $_FILES['file']['error'];
$fileType = $_FILES['file']['type'];
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array('png','jpg','mp3');
if (in_array($fileActualExt, $allowed)) {
if ($fileError === 0) {
if ($fileSize < 100000000) {
$fileNameNew = uniqid('', true).".".$fileActualExt;
$fileDestination = 'uploads/'.$fileNameNew;
move_uploaded_file($fileTmpName, $fileDestination);
# code...
}else {
echo "Your file is too big!";
}
} else {
echo "There was an error uploading your file!";
}
} else {
echo "You can't upload files of this type!";
}
// On insert nos données dans la table utilisateur
$DB->insert("INSERT INTO posts (content, author, fileNameNew) VALUES
(?, ?, ?)",
array($content, $author, $fileNameNew));
header('Location: home.php');
exit;
}
}
}
?>