Intégré mon code d'upload d'image dans la page.
Bonjour,
J'ai une page pour mettre modifié les données d'un utilisateur, j'ai le code pour uploader le tout mais je n'arrive pas à les mettre ensemble sur la même page.
Code:
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
| <?php
$poids_max = 512000; // Poids max de l'image en octets (1Ko = 1024 octets)
$repertoire = 'uploads/'; // Repertoire d'upload
if (isset($_FILES['fichier']))
{
// On vérifit le type du fichier
if ($_FILES['fichier']['type'] != 'image/png' && $_FILES['fichier']['type'] != 'image/jpeg' && $_FILES['fichier']['type'] != 'image/jpg' && $_FILES['fichier']['type'] != 'image/gif' && $_FILES['fichier']['type'] != 'image/bmp' && $_FILES['fichier']['type'] != 'image/jpg' && $_FILES['fichier']['type'] != 'image/png' && $_FILES['fichier']['type'] != 'image/ico')
{
$erreur = 'Le fichier doit être au format *.jpeg, *.bmp, *.jpg, *.png, *.ico *.gif ou *.png .';
}
// On vérifit le poids de l'image
elseif ($_FILES['fichier']['size'] > $poids_max)
{
$erreur = 'L\'image doit être inférieur à ' . $poids_max/1024 . 'Ko.';
}
// On vérifit si le répertoire d'upload existe
elseif (!file_exists($repertoire))
{
$erreur = 'Erreur, le dossier d\'upload n\'existe pas.';
}
// Si il y a une erreur on l'affiche sinon on peut uploader
if(isset($erreur))
{
echo '' . $erreur . '<br><a href="javascript:history.back(1)">Retour</a>';
}
else
{
// On définit l'extention du fichier puis on le nomme par le timestamp actuel
if ($_FILES['fichier']['type'] == 'image/jpeg') { $extention = '.jpeg'; }
if ($_FILES['fichier']['type'] == 'image/jpeg') { $extention = '.jpg'; }
if ($_FILES['fichier']['type'] == 'image/png') { $extention = '.png'; }
if ($_FILES['fichier']['type'] == 'image/gif') { $extention = '.gif'; }
if ($_FILES['fichier']['type'] == 'image/gif') { $extention = '.bmp'; }
if ($_FILES['fichier']['type'] == 'image/gif') { $extention = '.jpg'; }
if ($_FILES['fichier']['type'] == 'image/gif') { $extention = '.png'; }
if ($_FILES['fichier']['type'] == 'image/gif') { $extention = '.ico'; }
$nom_fichier = time().$extention;
// On upload le fichier sur le serveur.
if (move_uploaded_file($_FILES['fichier']['tmp_name'], $repertoire.$nom_fichier))
{
$url = 'www.monsite.com/'.$repertoire.''.$nom_fichier.'';
echo 'Votre image à été uploadée sur le serveur avec succes!<br>Voici le lien: <input type="text" value="' . $url . '" size="60">';
}
else
{
echo 'L\'image n\'a pas pu être uploadée sur le serveur.';
}
}
}
else
{
?>
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $poids_max; ?>">
<input type="file" name="fichier">
<input type="submit" value="Envoyer">
</form>
<?php
}
?> |
Après le code pour modifier mon utilisateur.
Qui renvois toutes les variables vers une page qui va faire les modifications dans la base de donnée.
Code:
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
| <form action="modifvalidation.php" method="post">
<input type="hidden" name="Id" value="<?php echo $id; ?>" size=30 />
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td width="50%" align="right">Initial </td>
<td width="50%">
<table border="0" bgcolor="" cellpadding=0 cellspacing=2>
<tr>
<td><input type="text" name="Initial" value="<?php echo $initial; ?>" size=30 /> </td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="50%" align="right">Nom </td>
<td width="50%">
<table border="0" bgcolor="" cellpadding=0 cellspacing=2>
<tr>
<td><input type="text" name="Nom" value="<?php echo $nom; ?>" size=30 /> </td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="50%" align="right">Prénom </td>
<td>
<table border="0" bgcolor="" cellpadding=0 cellspacing=2>
<tr>
<td><input type="text" name="Prenom" value="<?php echo $prenom; ?>" size=30 /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="50%" align="right">Numero</td>
<td>
<table border="0" bgcolor="" cellpadding=0 cellspacing=2>
<tr>
<td><input type="text" name="Numero" value="<?php echo $numero; ?>" size=30 /></td>
</tr>
</table>
</td>
</tr>
<td align="center" colspan="2"><input type="submit" value="Modifier" />
<a href="deletevalidation.php?Id=<?php echo "$id" ?>;"> <input type="button" value="Supprimer"> </a>
</td>
</table>
</form> |
En faite j'aimerai passé ".l'url." que je crée dans le code d'upload sur la page modifvalidation.php en meme temps que les autres variables.
Mais comme y'a 2 fois la balise "FORM" je ne sais pas comment intégré ça.
Si vous pouvez m'aider svp
merci