|
|
|
|
Bonjour,
mon objectif est de permettre le chargement de 3 images à partir d'un formulaire form.php; le script php se trouve dans le fichier chargement.php.
Dans form.php, à l'endroit où l'utilisateur doit cliquer pour charger l'image, j'appelle le fichier chargement.php ainsi:
include "chargement.php". Le problème est que l'image ne se charge pas. Par contre lorsque j'exécute chargement.php de façon isolée, le chargement de l'image s'effectue avec succès. Il y'a probablement un problème de transmission de données (le nom du fichier chargé peut-être) entre les 2 fichiers. Merci de m'aider à résoudre mon problème. Voici les codes:
<!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=iso-8859-1" /> <title>Document sans titre</title> </head> <body> <form action="" method="post" name="form1" class="Style1" enctype="multipart/form-data"> <table> <tr><!-- 3 images doivent être chargées--> <td><?php include "chargement.php" ?></td> <td><?php include "chargement.php" ?></td> <td><?php include "chargement.php" ?></td> </tr> </table> </form> </body> </html>
<html>
<head><title>Upload d'images</title>
<style type="text/css">
body {font-family:Arial, Verdana, sans-serif;font-size:0.8em;}
#bouton {background-color:#FF9900;}
</style>
</head>
<body>
<?php
//On paramétre la largeur, la hauteur et le poids maxi à ne pas dépasser.
$width_maxi = "300";
$height_maxi = "500";
$taille_maxi ="30720";//bytes
$fichier = $_FILES['fichier']['name'];
$taille=$_FILES['fichier']['size'];
$tmp = $_FILES['fichier']['tmp_name'];
$size_tmp=getimagesize ($tmp);
if ($fichier !="none")
{
if (($taille < $taille_maxi)&& ($size_tmp[0]<=$width_maxi)&&($size_tmp[1]<=$height_maxi))
{
$point=strrpos($fichier, ".");
if ($point)
$extension=substr ($fichier, $point);
else
$extension ="";
$date=date("ymdhis");
//indiquer l'url relative vers le dossier d'upload
$chemin="../images/suivi_photo/";
//un nouveau nom qui prend en compte la date, l'heure, les minutes
//et secondes est crée ; ainsi, aucune image ne peut être écrasée sur le serveur
$nouveau_nom = $chemin.$date.$extension;
if (move_uploaded_file($tmp, $nouveau_nom))
{
echo "Transfert du fichier réussi";
$size=getimagesize ($nouveau_nom);
echo "Largeur = ".$size[0]." pixels<br/>";
echo "Hauteur = ".$size[1]." pixels<br/>";
echo "Poids = ".$taille." octets<br/>";
form();
}
else
{
$taille_maxi_ko=$taille_maxi/1024;
echo "Transfert échoué<br/>";
echo "La largeur de l'image ne doit pas être supérieure à $width_maxi pixels.<br/>";
echo "La hauteur de l'image ne doit pas être supérieure à $height_maxi pixels.<br/>";
echo "Le fichier ne doit pas dépasser $taille_maxi_ko Ko.<br/>";
form();
}
}
else
{
$taille_maxi_ko=$taille_maxi/1024;
echo "Le fichier est trop lourd : envoi refusé<br/>
Le fichier ne doit pas dépasser $taille_maxi_ko Ko.<br/>";
echo "La largeur de l'image ne doit pas être supérieure
à $width_maxi pixels; elle fait ici $size_tmp[0] pixels<br/>";
echo "La hauteur de l'image ne doit pas être supérieure
à $height_maxi pixels ; elle fait ici $size_tmp[1] pixels<br/>";
form();
}
}
//le formulaire d'upload
function form()
{
global $taille_maxi;
echo '<hr/>
<form enctype="multipart/form-data" action="charger_img4.php" method="post">
<p><input type="hidden" name="max_file_size" value="36120" />
"Taille maximale du fichier acceptée: " . ($taille_maxi / 1024) . "Ko"
<input name="fichier" type="file" size="35" />
<input type="submit" value="Télécharger" id="bouton" />
</p>
</form>
</body></html>';
}
?>Configuration: Windows XP Firefox 2.0.0.6
Il faut plutot faire :
<form action="" method="post" name="form1" class="Style1" enctype="multipart/form-data" action="chargement.php"> <table> <tr><!-- 3 images doivent être chargées--> <td><input type="file" name="fichier1"></input></td> <td><input type="file" name="fichier2"></input></td> <td><input type="file" name="fichier3"></input></td> </tr> </table> </form> et après tu traite côté serveur avec chargement.php je n'ai pas testé. si tu n'es pas faché avec l'anglais vas voir ce lien pour une sol tte faite: http://the-stickman.com/... |
Merci pour vos réactions.
<?php
include "connexion.php";
form();
//le formulaire d'upload
function form()
{
global $taille_maxi;
global $php_code_agem; //recupération du code agem du fichier visites_march_trav.php
$date=date("ymdhis");
echo '<hr/>
<form enctype="multipart/form-data" action="" method="post">
<table width="80%" border="0" cellspacing="0" cellpadding="0" align="right">
<tr>
<td>
<input type="hidden" name="MAX_FILE_SIZE" value="500000">';
for($i = 1; $i <= 3; $i++)
{
echo 'image '.$i.' '.'<input type="file" name="photos[]"><br>';
}
echo '<input type="submit" name="btonEnvoyer" value="Envoyer les images">
</td>
</tr>
</table>
</form>';
if ($_POST['btonEnvoyer'])
{
$rep_destination = '../images/suivi_photo/';
$point=strrpos($_FILES['photos']['name'], ".");
if ($point)
$extension=substr($_FILES['photos']['name'],strlen($_FILES['photos']['name'])-4,4);
//$extension=substr($_FILES['photos']['name'], $point);
else
$extension ="";
foreach ($_FILES['photos']['name'] as $key => $value)
{
$nouveau_nom = $rep_destination.$php_code_agem.$date.$extension;
$uploadfile = $rep_destination . basename($_FILES['photos']['name'][$key]);
//echo $uploadfile;
if (move_uploaded_file($_FILES['photos']['tmp_name'][$key], $uploadfile))
{
rename(basename($_FILES['photos']['name'][$key]), $nouveau_nom);
echo ' image chargée avec succès! <br>';
requete="INSERT INTO suivi_photos( id, code_agem, photo1, photo2, photo3 ) VALUES ( '', '$php_code_agem', "$_FILES['photos']['name'][$key]" )";
mysql_query($requete);
}
}
}
}
?> |