par
mocoye » 27 avr. 2017, 12:26
Bonjour,
Comme vous vous en doutez je poste ce message car j'ai un problème, en effet je tente de créer une page qui permettra l'upload d'un fichier, j'ai donc repris les codes d'un autre site dans lequel cela fonctionne parfaitement et j'ai effectué les modifications nécessaires (nom des variables, adresse de dossiers,...), mais ça ne fonctionne pas.
Cela quelques semaines que je me rechercher, que je relis mon code, mais rien n'y fais, j'ai testé l'insertion des infos sans le fichier à uploader cela fonctionne bien, donc le problème vient du code d'upload mais je ne trouve pas l'erreur.
Je vous fais parvenir les 2 codes, celui du formulaire "ajout_ad.php" et celui du traitement "ajout_ad2.php"
ajout_ad.php :
Code : Tout sélectionner
<?php include("include/bdd.inc.php"); ?>
<!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" />
<title>AJOUT - ADHERENTS</title>
<link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico" />
<!--<link rel="icon" type="image/jpg" href="images/favicon.jpg">-->
<link href="css/reset.css" rel="stylesheet" type="text/css" />
<link href="css/menu.css" rel="stylesheet" type="text/css" />
<link href="css/design.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="contains">
<?php include("include/inc_header.php"); ?>
<?php include("include/inc_menu.php"); ?>
<div id="page" class="bor_general">
<div id="corps">
<div id="tit_corps">
<h2 class="gen">AJOUT D'ADHERENTS</h2>
<div class="clear"></div>
</div>
<form method="post" action="ajout_ad2.php" id="form" enctype="multipart/form-data" >
<table>
<tr>
<td width="120" class="tit_champ">NOM :</td>
<td width="600"><input name="ad_nom" type="text" id="nom" class="txt_champ" /></td>
</tr>
<tr>
<td width="119" class="tit_champ">ADRESSE :</td>
<td width="423"><input name="ad_adresse" type="text" id="adresse" class="txt_champ" /></td>
</tr>
<tr>
<td width="119" class="tit_champ">SITE :</td>
<td width="423"><input name="ad_site" type="text" id="site" class="txt_champ" /></td>
</tr>
<tr>
<td width="119" class="tit_champ">LOGO* :</td>
<td class="champfichier"><input type="hidden" name="MAX_FILE_SIZE" value="1000000" /><input name="avatar" type="file" /></td>
</tr>
<tr>
<td width="119" class="tit_champ">ACTIF</td>
<td class="champfichier"><input name="actif" type="checkbox" id="actif" /></td>
</tr>
<tr>
<td> </td>
<td><input name="envoyer" type="image" src="design/envoyer.png" value="envoyer" /></td>
</tr>
</table>
</form>
<p>* fichier ".png" - dimension : 200x150</p>
<div class="clear"></div>
</div>
<div id="bandeau">
<?php include("include/inc_bandeau_droit.php"); ?>
</div>
</div>
<div class="clear"></div>
</div>
<?php include("include/inc_footer.php"); ?>
</div>
<!--<div id="coprs">
<div id="tit_corps">
<h2 class="gen">LISTE DES ADHERENTS</h2>
<table width="680" border="0 ">
<tr>
<td width="30" class="tit_tab">N°</td>
<td width="150" class="tit_tab">NOM</td>
<td width="200" class="tit_tab">ADRESSE</td>
<td width="100" class="tit_tab">SITE</td>
<td width="120" class="tit_tab">LOGO</td>
<td width="50" class="tit_tab">Actif</td>
<td width="30" class="tit_tab">Sup.</td>
</tr>
<?php
$reponse = $bdd->query('SELECT * FROM adherents ORDER BY ad_nom');
while ($donnees = $reponse->fetch())
{
?> <tr>
<td class="result_tab"><?php echo htmlspecialchars($donnees['id']); ?></td>
<td class="result_tab"><?php echo htmlspecialchars($donnees['ad_nom']); ?></td>
<td class="result_tab"><?php echo htmlspecialchars($donnees['ad_adresse']); ?></td>
<td class="result_tab"><?php echo htmlspecialchars($donnees['ad_site']); ?></td>
<td class="result_tab"><?php echo htmlspecialchars($donnees['ad_logo']); ?></td>
<td class="result_tab"><?php echo htmlspecialchars($donnees['actif']); ?></td>
<td class="result_tab"><a href="javascript:if(confirm('Etes-vous sûr de vouloir supprimer cet adhérent : <?php echo addslashes($donnees['ad_nom']); ?> ?')){document.location.href='suppr_ad.php?id=<?php echo $donnees['id']; ?>';}">S</a></td>
</tr>
<?php
}
$reponse->closeCursor();
?>
</table>
<p> Pour ajouter un nouveau "adherent" : <a href="ajout_ad.php">CLIQUEZ ICI</a></p>
</div>
<div class="clear"></div>
</div>
<div id="bandeau">
<?php include("include/inc_bandeau_droit.php"); ?>
</div>
</div>
<?php include("include/inc_footer.php"); ?>
</div>-->
</body>
</html>
ajout_ad2.php :
Code : Tout sélectionner
<?php include("include/bdd.inc.php"); ?>
<?php
function filter($in) {
$search = array ('@[éèêëÊË]@i','@[àâäÂÄ]@i','@[îïÎÏ]@i','@[ûùüÛÜ]@i','@[ôöÔÖ]@i','@[ç]@i','@[ ]@','@[\']@');
$replace = array ('e','a','i','u','o','c','_','');
return preg_replace($search, $replace, $in);
}
$ad_nom=htmlspecialchars($_POST["ad_nom"]);
$ad_adresse=htmlspecialchars($_POST["ad_adresse"]);
$ad_site=htmlspecialchars($_POST["ad_site"]);
if(isset($_POST["actif"])){
echo $actif=1 ;
} else {
echo $actif=0;
}
if(isset($_FILES['ad_logo']))
{
$dossier = 'images/adherents/'; echo "<br>" .$dossier;
$ad_logo = basename($_FILES['ad_logo']['name']);echo "<br>" . $_FILES['ad_logo']['tmp_name'];
$taille_maxi = 1000000;
$taille = $_FILES['ad_logo']['size'];
$extensions = array('.png');
$extension = $_FILES['ad_logo']['type'];
//Début des vérifications de sécurité...
if(!file_exists($dossier)){
echo "<br> Erreur le dossier $dossier n'existe pas !";
}
if(!in_array($extension, $extensions)) //Si l'extension n'est pas dans le tableau
{
$erreur = '<br> Vous devez uploader un fichier de type png...';
}
if($taille>$taille_maxi)
{
$erreur = '<br> Le fichier est trop gros...';
}
if(!isset($erreur)) //S'il n'y a pas d'erreur, on upload
{
//On formate le nom du fichier ici...
$ad_logo = strtr($ad_logo,
'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ',
'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
$ad_logo = preg_replace('/([^.a-z0-9]+)/i', '-', $ad_logo);
if(move_uploaded_file($_FILES['ad_logo']['tmp_name'], $dossier . $ad_logo)) //Si la fonction renvoie TRUE, c'est que ça a fonctionné...
{
echo '<br> Upload a IMAGE effectué avec succès !';
}
else //Sinon (la fonction renvoie FALSE).
{
echo '<br> Echec de l\'upload IMAGE !';echo "<br> chemin de destination =>" . $dossier . $ad_logo;
}
}
else
{
echo $erreur;
}
$req = $bdd->prepare('INSERT INTO adherents(ad_nom, ad_adresse, ad_site, ad_logo, actif) VALUES (:ad_nom, :ad_adresse, :ad_site, :ad_logo, :actif)');
$req->execute(array(
'ad_nom' => $ad_nom,
'ad_adresse' => $ad_adresse,
'ad_site' => $ad_site,
'ad_logo' => $ad_logo,
'actif' => $actif
));
//header("location:liste_adherents.php");
}
?>
D'avance merci de vos retours,
Laetitia
Bonjour,
Comme vous vous en doutez je poste ce message car j'ai un problème, en effet je tente de créer une page qui permettra l'upload d'un fichier, j'ai donc repris les codes d'un autre site dans lequel cela fonctionne parfaitement et j'ai effectué les modifications nécessaires (nom des variables, adresse de dossiers,...), mais ça ne fonctionne pas.
Cela quelques semaines que je me rechercher, que je relis mon code, mais rien n'y fais, j'ai testé l'insertion des infos sans le fichier à uploader cela fonctionne bien, donc le problème vient du code d'upload mais je ne trouve pas l'erreur.
Je vous fais parvenir les 2 codes, celui du formulaire "ajout_ad.php" et celui du traitement "ajout_ad2.php"
ajout_ad.php :
[code]<?php include("include/bdd.inc.php"); ?>
<!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" />
<title>AJOUT - ADHERENTS</title>
<link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico" />
<!--<link rel="icon" type="image/jpg" href="images/favicon.jpg">-->
<link href="css/reset.css" rel="stylesheet" type="text/css" />
<link href="css/menu.css" rel="stylesheet" type="text/css" />
<link href="css/design.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="contains">
<?php include("include/inc_header.php"); ?>
<?php include("include/inc_menu.php"); ?>
<div id="page" class="bor_general">
<div id="corps">
<div id="tit_corps">
<h2 class="gen">AJOUT D'ADHERENTS</h2>
<div class="clear"></div>
</div>
<form method="post" action="ajout_ad2.php" id="form" enctype="multipart/form-data" >
<table>
<tr>
<td width="120" class="tit_champ">NOM :</td>
<td width="600"><input name="ad_nom" type="text" id="nom" class="txt_champ" /></td>
</tr>
<tr>
<td width="119" class="tit_champ">ADRESSE :</td>
<td width="423"><input name="ad_adresse" type="text" id="adresse" class="txt_champ" /></td>
</tr>
<tr>
<td width="119" class="tit_champ">SITE :</td>
<td width="423"><input name="ad_site" type="text" id="site" class="txt_champ" /></td>
</tr>
<tr>
<td width="119" class="tit_champ">LOGO* :</td>
<td class="champfichier"><input type="hidden" name="MAX_FILE_SIZE" value="1000000" /><input name="avatar" type="file" /></td>
</tr>
<tr>
<td width="119" class="tit_champ">ACTIF</td>
<td class="champfichier"><input name="actif" type="checkbox" id="actif" /></td>
</tr>
<tr>
<td> </td>
<td><input name="envoyer" type="image" src="design/envoyer.png" value="envoyer" /></td>
</tr>
</table>
</form>
<p>* fichier ".png" - dimension : 200x150</p>
<div class="clear"></div>
</div>
<div id="bandeau">
<?php include("include/inc_bandeau_droit.php"); ?>
</div>
</div>
<div class="clear"></div>
</div>
<?php include("include/inc_footer.php"); ?>
</div>
<!--<div id="coprs">
<div id="tit_corps">
<h2 class="gen">LISTE DES ADHERENTS</h2>
<table width="680" border="0 ">
<tr>
<td width="30" class="tit_tab">N°</td>
<td width="150" class="tit_tab">NOM</td>
<td width="200" class="tit_tab">ADRESSE</td>
<td width="100" class="tit_tab">SITE</td>
<td width="120" class="tit_tab">LOGO</td>
<td width="50" class="tit_tab">Actif</td>
<td width="30" class="tit_tab">Sup.</td>
</tr>
<?php
$reponse = $bdd->query('SELECT * FROM adherents ORDER BY ad_nom');
while ($donnees = $reponse->fetch())
{
?> <tr>
<td class="result_tab"><?php echo htmlspecialchars($donnees['id']); ?></td>
<td class="result_tab"><?php echo htmlspecialchars($donnees['ad_nom']); ?></td>
<td class="result_tab"><?php echo htmlspecialchars($donnees['ad_adresse']); ?></td>
<td class="result_tab"><?php echo htmlspecialchars($donnees['ad_site']); ?></td>
<td class="result_tab"><?php echo htmlspecialchars($donnees['ad_logo']); ?></td>
<td class="result_tab"><?php echo htmlspecialchars($donnees['actif']); ?></td>
<td class="result_tab"><a href="javascript:if(confirm('Etes-vous sûr de vouloir supprimer cet adhérent : <?php echo addslashes($donnees['ad_nom']); ?> ?')){document.location.href='suppr_ad.php?id=<?php echo $donnees['id']; ?>';}">S</a></td>
</tr>
<?php
}
$reponse->closeCursor();
?>
</table>
<p> Pour ajouter un nouveau "adherent" : <a href="ajout_ad.php">CLIQUEZ ICI</a></p>
</div>
<div class="clear"></div>
</div>
<div id="bandeau">
<?php include("include/inc_bandeau_droit.php"); ?>
</div>
</div>
<?php include("include/inc_footer.php"); ?>
</div>-->
</body>
</html>[/code]
ajout_ad2.php :
[code]<?php include("include/bdd.inc.php"); ?>
<?php
function filter($in) {
$search = array ('@[éèêëÊË]@i','@[àâäÂÄ]@i','@[îïÎÏ]@i','@[ûùüÛÜ]@i','@[ôöÔÖ]@i','@[ç]@i','@[ ]@','@[\']@');
$replace = array ('e','a','i','u','o','c','_','');
return preg_replace($search, $replace, $in);
}
$ad_nom=htmlspecialchars($_POST["ad_nom"]);
$ad_adresse=htmlspecialchars($_POST["ad_adresse"]);
$ad_site=htmlspecialchars($_POST["ad_site"]);
if(isset($_POST["actif"])){
echo $actif=1 ;
} else {
echo $actif=0;
}
if(isset($_FILES['ad_logo']))
{
$dossier = 'images/adherents/'; echo "<br>" .$dossier;
$ad_logo = basename($_FILES['ad_logo']['name']);echo "<br>" . $_FILES['ad_logo']['tmp_name'];
$taille_maxi = 1000000;
$taille = $_FILES['ad_logo']['size'];
$extensions = array('.png');
$extension = $_FILES['ad_logo']['type'];
//Début des vérifications de sécurité...
if(!file_exists($dossier)){
echo "<br> Erreur le dossier $dossier n'existe pas !";
}
if(!in_array($extension, $extensions)) //Si l'extension n'est pas dans le tableau
{
$erreur = '<br> Vous devez uploader un fichier de type png...';
}
if($taille>$taille_maxi)
{
$erreur = '<br> Le fichier est trop gros...';
}
if(!isset($erreur)) //S'il n'y a pas d'erreur, on upload
{
//On formate le nom du fichier ici...
$ad_logo = strtr($ad_logo,
'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ',
'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
$ad_logo = preg_replace('/([^.a-z0-9]+)/i', '-', $ad_logo);
if(move_uploaded_file($_FILES['ad_logo']['tmp_name'], $dossier . $ad_logo)) //Si la fonction renvoie TRUE, c'est que ça a fonctionné...
{
echo '<br> Upload a IMAGE effectué avec succès !';
}
else //Sinon (la fonction renvoie FALSE).
{
echo '<br> Echec de l\'upload IMAGE !';echo "<br> chemin de destination =>" . $dossier . $ad_logo;
}
}
else
{
echo $erreur;
}
$req = $bdd->prepare('INSERT INTO adherents(ad_nom, ad_adresse, ad_site, ad_logo, actif) VALUES (:ad_nom, :ad_adresse, :ad_site, :ad_logo, :actif)');
$req->execute(array(
'ad_nom' => $ad_nom,
'ad_adresse' => $ad_adresse,
'ad_site' => $ad_site,
'ad_logo' => $ad_logo,
'actif' => $actif
));
//header("location:liste_adherents.php");
}
?>[/code]
D'avance merci de vos retours,
Laetitia