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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
| <?php
include('../bdd.php');
if(!empty($_POST))
{
extract($_POST);
$validation = true;
if(empty($titre) || empty($artiste))
{
$validation = false;
$input_error ='Remplissez tous les champs';
}
if(!isset($_FILES['source']) || $_FILES['source']['error'] >0)
{
$validation = false;
$file_error = 'Indiquez une source audio';
}
else
{
$infos = pathinfo($_FILES['source']['name']);
if($infos['extensions'] != 'ogg')
{
$validation = false;
$file_error ='Votre fichier doit être au format ogg';
}
}
if($_FILES['source']['size'] > 10000000)
{
$validation = false;
$file_error ='Votre fichier est trop volumineux (> à 10Mo)';
}
if($validation)
{
move_uploaded_file($_FILES['source']['tmp_name'],'../musiques/'.$_FILES['source']['name']);
$req = $bdd->prepare("INSERT INTO playlist (titre, artiste, source) VALUES(:titre,:artiste,:source)");
$req->execute(array(
'titre' => $titre,
'artiste' => $artiste,
'source' => $_FILES['source']['name']
));
$req->closeCursor();
$ok = 'Enregistrement effectué !';
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--appel de la police google font-->
<link href='http://fonts.googleapis.com/css?family=Open+Sans+Condensed:300,700' rel='stylesheet' type='text/css' />
<!--appel css-->
<link rel="stylesheet" type="text/css" href="../styles/style.css"/>
<link rel="stylesheet" type="text/css" href="../styles/playlist.css"/>
<title>Document sans nom</title>
</head>
<body>
<!--debut section menu-->
<section id="main">
<!--debut section contenu-->
<section id="contenu">
<h1>Bienvenue</h1>
<!--debut player-->
<section>
<div class="remove"></div>
<div><strong>Ajouter une musique dans la playlist :</strong></div>
<?php if(isset($input_error))echo'<div class="error">- '.$input_error.'</div>';?>
<?php if(isset($file_error))echo'<div class="error">- '.$file_error.'</div>';?>
<?php if(isset($ok))echo'<div class="error">- '.$ok.'</div>';?>
<form method="post" enctype="multipart/form-data">
<input type="text" name="titre" placeholder="Titre de la musique" value="<?php if(isset($titre))echo $titre; ?>" />
<input type="text" name="artiste" placeholder="Nom de l'artiste" value="<?php if(isset($artiste))echo $artiste; ?>" />
<input type="file" name="source" />
<input type="submit" value="Ajouter dans lap laylist" />
</form>
<table class="bordered">
<thead>
<td></td>
<td class="titre">Titre</td>
<td class="artiste">Artiste</td>
</thead>
<?php
include('../bdd.php');
$select = $bdd->query("SELECT * FROM playlist ORDER BY titre");
$compteur = 0;
while($donnees = $select->fetch())
{
?>
<tr <?php if($compteur % 2 == 0){echo 'class="blanc"';}else{echo 'class="gris"';} ?>>
<td><button class="removeIcon" tittle="Supprimer" onclick="supprimer('<?php echo str_replace("'","\'",$donnees['titre']); ?>','<?php echo str_replace("'","\'",$donnees['artiste']); ?>','<?php echo $donnees['id']; ?>')"></button></td>
<td><?php echo $donnees['titre']; ?></td>
<td><?php echo $donnees['artiste']; ?></td>
</tr>
<?php
$compteur += 1;
}
$select->closeCursor();
?>
</table>
<script>
function supprimer(titre,artiste,id){
var remove = document.querySelector('.remove');
remove.style.display ='block';
remove.innerHTML ='<a href="remove.php?id=' + id + '">Supprimer définitivement <strong>' + titre + '</strong> de ' + artiste + '</a>';
}
</script>
</section>
<!--fin player-->
</section>
<!--fin section contenu-->
</section>
<!--fin section menu-->
</div>
<!--fin wrapper-->
</body>
</html> |
Partager