bonjour j'ai un soucis. Je vousdrais savoir s'il est possible d'uploader plusieurs fichiers mp3 a la fois. Moi je n'y arrive pas. Voici mon code.
<?php
@session_start();
include"structclass.php";
include"imageresizer.php";
if($_SERVER['REQUEST_METHOD']=="POST" ){
$servid=$_SESSION['servid'];
$typeadmin=$_SESSION['admintype'];
$nom = htmlspecialchars_decode($_POST['nom']);
$year=checkitall($_POST['year']);
$description=html_entity_decode($_POST['description'])?html_entity_decode($_POST['description']) :'';
$img=$_FILES['pic'];
$albumid=generateUniqueToken(6,"ad_album","albumid","");
$mp3=$_FILES['mp3'];
if(empty($_POST['nom']))
{
setFlash("Veuillez renseigner le titre de l'album");
header("location:dashboard.php?parcours=discographie");
die();
}
if(empty($_POST['year']))
{
setFlash("Veuillez renseigner l'année de parution de l'album");
header("location:dashboard.php?parcours=discographie");
die();
}
if(empty($_POST['description']))
{
setFlash("Veuillez renseigner une description de l'album");
header("location:dashboard.php?parcours=discographie");
die();
}
//mise en place du chemin du dossier pour les sons
$dossier='';
switch($typeadmin)
{
case"AR":
$dossier="../membres/artistes/".$servid."/album";
break;
}
// image de couverture de l'album
$dossierpic='';
switch($typeadmin)
{
case"AR":
$dossierpic="../membres/artistes/".$servid."/album";
break;
}
//Vérification de l'existence de l'album
require"connectionbd.php";
$req="select * from ad_album where nom=:id and ownerid=:s";
$res=$bdd->prepare($req);
$res->execute(array('id'=>$nom,'s'=>$servid));
$v=$res->rowCount();
if($v==0) {
if ($_FILES["pic"]["error"])
{
echo "code d'erreur: " . $_FILES["pic"]["error"] . "<br>";
}
$ext=strtolower(substr(strrchr($img['name'],'.'),1));
$auto_ext=array('jpg','gif','jpeg','png');
if(in_array($ext,$auto_ext))
{
if(!is_dir($dossierpic))
{
mkdir($dossier,0777);
}
if(file_exists($dossierpic.'/'.$img['name'].'.'.$ext))
{
setFlash("l'image existe déjà","danger");
header("location:dashboard.php?parcours=discographie");
die();
}
else
{
$img['name']=str_replace(' ','',$albumid).'.png';
move_uploaded_file($img['tmp_name'],$dossierpic.'/'.$img['name']);
$dosimg=$dossierpic.'/'.$img['name'];
}
}
else
{
setFlash("Veuillez selectionnez un fichier image","danger");
header("location:dashboard.php?parcours=discographie");
die();
}
//Traitement du fichier mp3
foreach($mp3['tmp_name'] as $key => $tmp_name)
{
if ($mp3["error"][$key] > 0)
{
echo "code d'erreur: " . $mp3["error"][$key] . "<br>";
}
else
{
if($mp3['size'][$key]>10000000)
{
setFlash("Le fichier n°". $key ." est trop grand","danger");
header("location:dashboard.php?parcours=discographie");
die();
}
else
{
$ext=strtolower(substr(strrchr($mp3['name'][$key],'.'),1));
$auto_ext=array('mp3','mpeg');
if(in_array($ext,$auto_ext))
{
if(!is_dir($dossier.'/'.$albumid))
{
mkdir($dossier.'/'.$albumid,0777);
}
if(file_exists($dossier.'/'.$albumid.'/'.$mp3['name'][$key].'.'.$ext))
{
setFlash("le fichier existe déjà existe déjà","danger");
header("location:dashboard.php?parcours=discographie");
die();
}
else
{
$mp3['name']=str_replace(' ','',$mp3['name']);
move_uploaded_file($mp3['tmp_name'][$key],$dossier.'/'.$albumid.'/'.$mp3['name'][$key]);
//Insertion des fichiers audios dans la bdd
}
}
elseif(!in_array($ext,$auto_ext))
{
setFlash("Le fichier choisi n'est pas un fichier audio","danger");
header("location:dashboard.php?parcours=discographie");
die();
}
}
}
}
try
{
$req="insert into ad_album(nom,year,nbrtitre,descrip,albumpic,albumid,ownerid) values(:n,:y,:nb,:des,:alb,:albid,:o)";
$res=$bdd->prepare($req);
$res->execute(array('n'=>$nom,'y'=>$year,'nb'=>$key+1,'des'=>$description,'alb'=>$dosimg,'albid'=>$albumid,'o'=>$servid));
setFlash("VOTRE ALBUM A BIEN ETE AJOUTE");
header("location:dashboard.php?parcours=discographie");
die();
}
catch(Exception $e)
{
die('Erreur : ' . $e->getMessage().' a la ligne '.$e->getLine().' dans le fichier '.$e->getFile());
}
}
else
{
setFlash("Cet album existe déjà","danger");
header("location:dashboard.php?parcours=discographie");
die();
}
}
?>
Notice: Undefined index: nom in C:\wamp\www\termine\newadmin\discographietraitement.php on line 9
Notice: Undefined index: year in C:\wamp\www\termine\newadmin\discographietraitement.php on line 10
Notice: Undefined index: description in C:\wamp\www\termine\newadmin\discographietraitement.php on line 11
Notice: Undefined index: pic in C:\wamp\www\termine\newadmin\discographietraitement.php on line 12
Notice: Undefined index: mp3 in C:\wamp\www\termine\newadmin\discographietraitement.php on line 14
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\termine\newadmin\discographietraitement.php:14) in C:\wamp\www\termine\newadmin\discographietraitement.php on line 18.
Tes variables n'ont pas l'air de passer. Essais de debuger le contenu de $_FILES
et $_POST
voir si tu récupères bien toutes les valeurs dont tu as besoins.
Quand à l'erreur concernant le header, si mes souvenirs sont bons les sessions doivent êtres lancées avant tout code html dans tes pages, à regarder.