upload image filesystem

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : upload image filesystem

par golfinha » 30 juin 2009, 14:30

Okok c'est fait!
Alors j'ai:

Code : Tout sélectionner

Notice: A session had already been started - ignoring session_start() in C:\xampplite\htdocs\Site Punch\admin\security.php on line 2 Notice: Undefined index: nom in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 9 Notice: Undefined index: prenom in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 10 Notice: Undefined index: id_type_de_prospection in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 11 Notice: Undefined index: prix_annonce in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 12 Notice: Undefined index: prix_min in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 13 Notice: Undefined index: rue in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 14 Notice: Undefined index: code_postal in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 15 Notice: Undefined index: code_postal in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 16 Notice: Undefined index: commune in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 17 Notice: Undefined index: pays in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 18 Notice: Undefined index: id_type_de_bien in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 19 Notice: Undefined index: reference in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 20 Notice: Undefined index: annee_construction in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 21 Notice: Undefined index: annee_renovation in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 22 Notice: Undefined index: libre_le in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 23 Notice: Undefined index: loue_jusque in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 24 Notice: Undefined index: revenu_locatif_mensuel in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 25 Notice: Undefined index: proximite_0 in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 26 Notice: Undefined index: proximite_1 in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 27 Notice: Undefined index: proximite_2 in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 28 Notice: Undefined index: proximite_3 in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 29 Notice: Undefined index: proximite_4 in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 30 Notice: Undefined index: proximite_5 in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 31 Notice: Undefined index: proximite_6 in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 32 Notice: Undefined index: id_type_quartier in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 33 Notice: Undefined index: cadastre_denomination1 in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 34 Notice: Undefined index: cadastre_denomination2 in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 35 Notice: Undefined index: cadastre_numero in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 36 Notice: Undefined index: cadastre_superficie in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 37 Notice: Undefined index: cadastre_description_generale in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 38 Notice: Undefined index: imposition_rc_non_indexe in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 39 Notice: Undefined index: imposition_rc_indexe in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 40 Notice: Undefined index: precompte_immoblier in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 41 Notice: Undefined index: commentaire_imposition in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 42 Notice: Undefined index: restriction_servitude in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 43 Notice: Undefined index: restriction_permis in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 44 Notice: Undefined index: restriction_commentaire in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 45 Notice: Undefined index: piece_debarras in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 74 Notice: Undefined index: superficie_debarras in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 75 Notice: Undefined index: piece_grenier in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 76 Notice: Undefined index: superficie_grenier in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 77 Notice: Undefined index: piece_cave in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 78 Notice: Undefined index: superficie_cave in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 79 Notice: Undefined index: nbre_piece_bureau in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 80 Notice: Undefined index: piece_atelier in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 81 Notice: Undefined index: superficie_atelier in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 82 Notice: Undefined index: piece_veranda in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 83 Notice: Undefined index: superficie_veranda in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 84 Notice: Undefined index: nbre_garage in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 85 Notice: Undefined index: nbre_parking in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 86 Notice: Undefined index: piece_terrasse in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 87 Notice: Undefined index: superficie_terrasse in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 88 Notice: Undefined index: piece_balcon in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 89 Notice: Undefined index: superficie_balcon in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 90 Notice: Undefined index: piece_jardin in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 91 Notice: Undefined index: superficie_jardin in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 92 Notice: Undefined index: feu in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 95 Notice: Undefined index: citerne in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 99 Notice: Undefined index: hydrophore in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 101 Notice: Undefined index: fosse in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 102 Notice: Undefined index: egouts in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 103 Notice: Undefined index: telephone in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 104 Notice: Undefined index: tv in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 105 Notice: Undefined index: internet in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 106 Notice: Undefined index: type_de_charge in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 110 Notice: Undefined index: compteur_separe in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 111 Notice: Undefined index: photo_01 in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 115 Notice: Undefined index: photo_01 in C:\xampplite\htdocs\Site Punch\admin\encodage_bien4.php on line 215
Je viens de voir que déjà qqc qui manquait dans mon code....

par Yosh » 30 juin 2009, 14:16

Oulala,

le code error_reporting c'est du PHP...

donc fait plutôt
<?php 
session_start();
error_reporting(E_ALL);
require_once('security.php');
?>
En gros tu met le code dans les balises PHP

par golfinha » 30 juin 2009, 14:07

J'ai ceci comme erreur

Code : Tout sélectionner

error_reporting(E_ALL); Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampplite\htdocs\Site Punch\admin\encodage_bien5.php:2) in C:\xampplite\htdocs\Site Punch\admin\security.php on line 2
et dans ma page php, j'ai mis

Code : Tout sélectionner

<?php session_start();?> error_reporting(E_ALL); <?php require_once('security.php')?> <?php require_once('../Connections/connect.php'); ?> <?php require_once('../fonction2.php'); ?> <?php $_SESSION["nom"] = htmlspecialchars($_POST['nom']); $_SESSION["prenom"] = htmlspecialchars($_POST['prenom']); ...

par Yosh » 30 juin 2009, 13:33

OK, donc commence par ta session_start puis le error_reporting puis les include.

par golfinha » 30 juin 2009, 13:20

je commence comme ceci ma page

Code : Tout sélectionner

<?php require_once('security.php')?> <?php require_once('../Connections/connect.php'); ?> <?php session_start();?>
dans un autre formulaire que j'ai réalisé, je pratique de la meme sorte et je n'ai pas de problème.

J'ai l'impression que mon problème se situe dans le code php de la page du formulaire, ou dans le code php de la page fonction2.php.
Est ce que ce code est bien correcte?
Merci

par Kiwix » 30 juin 2009, 12:52

Au niveau des erreurs de session, verifie que session_start (); soit présent sur toutes tes pages, ainsi que leurs ligne de stript. Les header doivent être déclaré avant tout ! donc ta premiere ligne doit commencer par session_start (); . C'est le même principe pour la variable superglobal tel qu'un cookie.

par golfinha » 30 juin 2009, 12:30

j'ai ceci comme erreur

Code : Tout sélectionner

error_reporting(E_ALL); Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampplite\htdocs\Site Punch\admin\encodage_bien5.php:2) in C:\xampplite\htdocs\Site Punch\admin\security.php on line 2 Warning: Cannot modify header information - headers already sent by (output started at C:\xampplite\htdocs\Site Punch\admin\encodage_bien5.php:2) in C:\xampplite\htdocs\Site Punch\admin\security.php on line 5

par Yosh » 30 juin 2009, 12:00

il faudrait que tu affiche les erreurs renvoyé par PHP.

Et rajouter au tout début de ton fichier
error_reporting(E_ALL);
EDIT:

Vérifie tes arguments quand tu appel upload_img car apparement tu passe 6 arguments à ta fonction qui n'en attend que 5, le paramètre manquant étant le path de destination.

par golfinha » 30 juin 2009, 11:30

Le voici:

Code : Tout sélectionner

<form method="POST" action="encodage_bien5.php" enctype="multipart/form-data" name="formulaire_bien"> <input type="hidden" name="MAX_FILE_SIZE" value="2000000" /> <table width="464" border="0" class="Style_texte1"> <tr> <td colspan="2" class="Style_News">Insertion de photographies</td> </tr> <tr> <td class="Style10"><p> <input type="file" name="photo_01" id="photo_01" /> </p> </td> <td class="Style10"><input type="file" name="photo_06" id="photo_06" /></td> </tr> <tr> <td class="Style10"><input type="file" name="photo_02" id="photo_02" /></td> <td class="Style10"><input type="file" name="photo_07" id="photo_07" /></td> </tr> <tr> <td class="Style10"><input type="file" name="photo_03" id="photo_03" /></td> <td class="Style10"><input type="file" name="photo_08" id="photo_08" /></td> </tr> <tr> <td class="Style10"><input type="file" name="photo_04" id="photo_04" /></td> <td class="Style10"><input type="file" name="photo_09" id="photo_09" /></td> </tr> <tr> <td class="Style10"><input type="file" name="photo_05" id="photo_05" /></td> <td class="Style10"><input type="file" name="photo_10" id="photo_10" /></td> </tr> <tr> <td colspan="2" class="Style_News">Dossier</td> </tr> <tr> <td>Responsable du dossier</td> <td><?php mysql_select_db($database_connect, $connect); $result = mysql_query("SELECT id_ident, responsable_dossier FROM ident"); $menuDeroulant = '<SELECT>'; while ($row = mysql_fetch_object($result)) { $menuDeroulant .= '<OPTION value="'.$row->id_ident.'">'.$row->responsable_dossier.'</OPTION>'; } $menuDeroulant .= '</SELECT>'; echo $menuDeroulant; ?></td> </tr> <tr> <td width="150" ><INPUT type="button" name="preview" value="< Pr&eacute;c&eacute;dent" onClick="history.back()"></td> <td width="150"><input type="submit" name="Submit" value="Sauvegarder"></td> </tr> </table> </form>

par Yosh » 30 juin 2009, 11:29

Montre nous le code du formulaire.

upload image filesystem

par golfinha » 30 juin 2009, 11:28

Bonjour!
J'ai un formulaire de contact et je souhaite enregistrer plusieurs photos.
On va commencer par une.

Je souhaite enregistrer à la fois une image redimensionnée en 400px / 400 px mx et une miniature de 50px / 50px. J'ai choisi la méthode d'enregistrement dans le filesystem (avec un lien id_photo dans la db), j'ai donc un dossier /upload, et un dossier /upload/vignette.

Dans mon code html, j'ai ceci

Code : Tout sélectionner

<input type="file" name="photo_01" id="photo_01" />
Dans le code php:

Code : Tout sélectionner

<?php require_once('../fonction2.php'); ?> <?php if($_FILES['photo_01']) { $format_ok = array( "image/pjpeg" => ".jpg", "image/jpeg" => ".jpg", "image/jpeg" => ".JPG", "image/gif" => ".gif", "image/png" => ".png", ); $type_file = $_FILES['photo_01']['type']; phpinfo(32); if($_FILES['photo_01']['error'] == 0) //qd = à 0 c qu'il n'y a pas d'erreur { if(isset($formats_ok[$type_file])) { $new_path = "upload/"; $extension = $formats_ok[$type_file]; $photo_01 = date("ymdhis").$extension; $last_path = $_FILES['photo_01']['tmp_name']; $photo_01 = $new_path.$photo_01; move_uploaded_file($last_path,$photo_01); // redimension image $file=$photo_01; $hauteur=400; $largeur=400; //recup taille du photo $size=getimagesize($file); //print_r($size); $largeur_origine=$size[0]; $hauteur_origine=$size[1]; //copie de l'image du HD vers mémoire du serveur dans $src if($size['mime']=="image/jpeg" OR $size['mime']=="image/pjpeg") { $src = imagecreatefromjpeg($file); } elseif($size['mime']=="image/png") { $src = imagecreatefrompng($file); } //caul des dimensions finales $ratio_x=$largeur/$largeur_origine; $ratio_y=$hauteur/$hauteur_origine; if($ratio_x>=1 and $ratio_y>=1)//si image plus petite que canevas { $largeur_finale=$largeur_origine; $hauteur_finale=$hauteur_origine; } elseif($ratio_x < $ratio_y)//si largeur nettement plus petite { //echo "redim ratio_x <br>"; $largeur_finale=$largeur; $hauteur_finale=ceil($hauteur_origine*$ratio_x); } else //inverse { //echo "redim ratio_y <br>"; $largeur_finale=ceil($largeur_origine*$ratio_y); $hauteur_finale=$hauteur; } /*echo "dimensions de départ=$largeur_origine x $hauteur_origine<br>"; echo "dimensions max d'affichage = $largeur x $hauteur<br>"; echo "dimension_calculée=$largeur_finale x $hauteur_finale<br>"; echo "ratios=$ratio_x and $ratio_y"; exit;*/ //création de l'image de réception aux dimensions calculées $dst = imagecreatetruecolor($largeur_finale,$hauteur_finale); //copie de l'image origine ($src) dans l'image réception ($dst) en redimensionnant imagecopyresized($dst,$src,0,0,0,0,$largeur_finale,$hauteur_finale,$largeur_origine,$hauteur_origine); $gris = imagecolorallocate($dst,125, 125, 125); imagestring($dst,2,2,2,$copyright,$gris); if($_FILES['photo_01']) { include("fonction2.php"); $date=date("ymdhis"); upload_img("photo",400,400,$date,$nom,"upload/"); upload_img("photo",50,50,$date,"upload/vignettes/"); } //fermeture test existance du photo //header("content-type: image/jpeg");//affiche image imagejpeg($dst,$file,80);//ecrit image sur disque dur //imagejpeg($dst,$new_file,80);//renvoie image au navigateur imagedestroy($src); imagedestroy($dst); //end redimension image } else {echo 'erreur de format';} } } ?> <?php if($_FILES['photo_01']) { $date=date("ymdhis"); upload_img("photo_01",400,400,$date,"upload/"); upload_img("photo_01",50,50,$date,"upload/vignettes/"); // virer car pas de vignettes } //fermeture test existance du fichier ?>
Dans mon fichier fonction2.php, j'ai ceci

Code : Tout sélectionner

<?php function affiche_date ($date,$glue="/") { $array=explode('-',$date); $chaine=$array[2].$glue.$array[1].$glue.$array[0]; return $chaine; } function convert_date($date,$glue="-") { $array=explode('/',$date); $chaine=$array[2].$glue.$array[1].$glue.$array[0]; return $chaine; } ?> <?php function affiche_img($nom,$chemin,$format,$alt_text,$large) { $photo_01 = $chemin.$nom.$format; if(file_exists($photo_01)) { echo "<img src=\"$photo_01\" width=\"$large\" alt=\"$alt_text\" />"; } } function upload_img($champ,$largeur=400,$hauteur=400,$nom) { if($_FILES['photo_01']) { $format_ok = array( "image/pjpeg" => ".jpg", "image/jpeg" => ".jpg", "image/jpeg" => ".JPG", "image/gif" => ".gif", "image/png" => ".png", ); $type_file = $_FILES['photo_01']['type']; phpinfo(32); if($_FILES['photo_01']['error'] == 0) //qd = à 0 c qu'il n'y a pas d'erreur { if(isset($formats_ok[$type_file])) { $new_path = "upload/"; $extension = $formats_ok[$type_file]; $photo_01 = date("ymdhis").$extension; $last_path = $_FILES['photo_01']['tmp_name']; $photo_01 = $new_path.$photo_01; move_uploaded_file($last_path,$photo_01); // redimension image $file=$photo_01; $hauteur=400; $largeur=400; //recup taille du photo $size=getimagesize($file); //print_r($size); $largeur_origine=$size[0]; $hauteur_origine=$size[1]; //copie de l'image du HD vers mémoire du serveur dans $src if($size['mime']=="image/jpeg" OR $size['mime']=="image/pjpeg") { $src = imagecreatefromjpeg($file); } elseif($size['mime']=="image/png") { $src = imagecreatefrompng($file); } //caul des dimensions finales $ratio_x=$largeur/$largeur_origine; $ratio_y=$hauteur/$hauteur_origine; if($ratio_x>=1 and $ratio_y>=1)//si image plus petite que canevas { $largeur_finale=$largeur_origine; $hauteur_finale=$hauteur_origine; } elseif($ratio_x < $ratio_y)//si largeur nettement plus petite { //echo "redim ratio_x <br>"; $largeur_finale=$largeur; $hauteur_finale=ceil($hauteur_origine*$ratio_x); } else //inverse { //echo "redim ratio_y <br>"; $largeur_finale=ceil($largeur_origine*$ratio_y); $hauteur_finale=$hauteur; } /*echo "dimensions de départ=$largeur_origine x $hauteur_origine<br>"; echo "dimensions max d'affichage = $largeur x $hauteur<br>"; echo "dimension_calculée=$largeur_finale x $hauteur_finale<br>"; echo "ratios=$ratio_x and $ratio_y"; exit;*/ //création de l'image de réception aux dimensions calculées $dst = imagecreatetruecolor($largeur_finale,$hauteur_finale); //copie de l'image origine ($src) dans l'image réception ($dst) en redimensionnant imagecopyresized($dst,$src,0,0,0,0,$largeur_finale,$hauteur_finale,$largeur_origine,$hauteur_origine); $gris = imagecolorallocate($dst,125, 125, 125); imagestring($dst,2,2,2,$copyright,$gris); if($_FILES['photo_01']) { include("fonction2.php"); $date=date("ymdhis"); upload_img("photo",400,400,$date,$nom,"upload/"); upload_img("photo",50,50,$date,"upload/vignettes/"); } //fermeture test existance du photo //header("content-type: image/jpeg");//affiche image imagejpeg($dst,$file,80);//ecrit image sur disque dur //imagejpeg($dst,$new_file,80);//renvoie image au navigateur imagedestroy($src); imagedestroy($dst); //end redimension image } else {echo 'erreur de format';} } } } ?>
Malheureusement, ca ne fonctionne pas, ou ce trouve l'erreur?