Bah justement je n'y arrive pas.
j'ai fais comme ça
et ça me dis que "url" n'est pas défini
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
|
<?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.'';
}
}
}
else
{
?>
<form action="modifvalidation.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="Id" value="<?php echo $id; ?>" size=30 />
<input type="hidden" name="Photo" value="<?php echo $url; ?>" size=30 />
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td width="50%" align="right">Initial </td>
<td width="50%"><input type="text" name="Initial" value="<?php echo $initial; ?>" size=30 /> </td>
</tr>
<tr>
<td width="50%" align="right">Nom </td>
<td width="50%"><input type="text" name="Nom" value="<?php echo $nom; ?>" size=30 /> </td>
</tr>
<tr>
<td width="50%" align="right">Prénom </td>
<td width="50%"><input type="text" name="Prenom" value="<?php echo $prenom; ?>" size=30 /> </td>
</tr>
<tr>
<td width="50%" align="right">Numero </td>
<td width="50%"><input type="text" name="Numero" value="<?php echo $numero; ?>" size=30 /> </td>
</tr>
<tr>
<td width="50%" align="right">Societé </td>
<td width="50%"><input type="text" name="Societe" value="<?php echo $societe; ?>" size=30 /> </td>
</tr>
<tr>
<td align="center" colspan="2">
<a href="deletevalidation.php?Id=<?php echo "$id" ?>;"> <input type="button" value="Supprimer"> </a></td>
</tr>
</table>
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $poids_max; ?>">
<input type="file" name="fichier">
<input type="submit" value="Envoyer">
</form>
<?php
}
?> |
Notice: Undefined variable: url in C:\Program Files (x86)\EasyPHP5.2.10\www\test\test.php on line 62
'..'
<input type="hidden" name="Photo" value="<?php echo $url; ?>" size=30 />
ça ne m'upload même plus les images.
Y'a il faut adapté le code pour les implantés l'un dans l'autre mais compliquer avec les vérifications et tout.
Partager