Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1205 connectés 

  FORUM HardWare.fr
  Programmation
  PHP

  Prob upload & unlink

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Prob upload & unlink

n°1608666
moutonton
Posté le 05-09-2007 à 19:53:15  profilanswer
 

Hello.
J'ai un script afin de modifier une image d'un enregistrement. Lorsque j'upload, l'ancienne image s'efface comme convenu par contre la nouvelle image ne remplace pas l'ancienne dans la BDD.
 
voici le code :
 

Code :
  1. //définition du chemin relatif par rapport à la page ajouter_offres.php et de la variable obj_image qui contiendra le nom du fichier
  2. $uploaddir = '../../image/';
  3. //on test si on a déja un fichier, si oui, on initialise la variable $obj_image
  4. if(isset($_POST['obj_img_old'])) {
  5. $obj_image=$_POST['obj_img_old'];
  6. }
  7. else{
  8. $obj_image="";
  9. }
  10. //on test que l'utilisateur ait bien sélectionné un fichier
  11. if((isset($_FILES['obj_image']['name'])) && ($_FILES['obj_image']['name']!="" )){
  12. //on déplace le fichier dans le répertoire
  13. if(move_uploaded_file($_FILES['obj_image']['tmp_name'],$uploaddir.$_FILES['obj_image']['name']))
  14. {
  15.  $obj_image=$_FILES['obj_image']['name'];
  16.  //redimentionner l'image
  17.  creation_vignette($obj_image, 150,150, $uploaddir, $uploaddir, "../image/vignette/vignette_" );
  18. //on efface le fichier
  19.  if((isset($_POST['obj_img_old'])) && ($_POST['obj_img_old']!="" )){
  20.    unlink($uploaddir.'/'.$_POST['obj_img_old']);
  21.   }
  22. }
  23. }


 
le champ "obj_img_old" contient l'image actuelle s'il y en a une(donc celle qui va être remplacée)
le champ "obj_image" est donc le champ qui contient l'image (donc uploader)
 
Help me please

mood
Publicité
Posté le 05-09-2007 à 19:53:15  profilanswer
 

n°1608671
bixibu
Ca ... c'est fait!
Posté le 05-09-2007 à 20:22:03  profilanswer
 

heu la tu nous dit que l'update de la BDD ne marche pas, mais ca parait normal vu qu'il n'y a aucun code en rapport avec   une base de donnée! ou tu as peut etre oublié de poster un morceau de ton code?
 
la tu l'efface du repertoire mais tu touche pas du tout à la bdd

n°1608677
moutonton
Posté le 05-09-2007 à 20:46:04  profilanswer
 

Voici le principal pour le formulaire de MAJ :
 

Code :
  1. $editFormAction = $_SERVER['PHP_SELF'];
  2. if (isset($_SERVER['QUERY_STRING'])) {
  3.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  4. }
  5. if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1" )) {
  6.   $updateSQL = sprintf("UPDATE t_objet SET obj_type=%s, obj_libelle=%s, obj_image=%s, obj_prix=%s, obj_divers=%s, obj_dimension=%s, obj_contraste=%s, obj_luminosite=%s, obj_resolution=%s, obj_angle=%s, obj_operateur=%s, obj_caracteristique=%s, obj_puissance=%s, obj_chargeurcd=%s, obj_cassette=%s, obj_tuner=%s, obj_GEQ=%s, obj_enregistreur=%s, obj_disquedur=%s, obj_gravure=%s, obj_lecture=%s, obj_mar_numero=%s WHERE obj_numero=%s",
  7.                        GetSQLValueString($_POST['obj_type'], "text" ),
  8.                        GetSQLValueString($_POST['obj_libelle'], "text" ),
  9.                        GetSQLValueString($obj_image, "text" ),
  10.                        GetSQLValueString($_POST['obj_prix'], "text" ),
  11.        GetSQLValueString($_POST['obj_prix_stoller'], "text" ),
  12.                        GetSQLValueString($_POST['obj_divers'], "text" ),
  13.                        GetSQLValueString($_POST['obj_dimension'], "text" ),
  14.                        GetSQLValueString($_POST['obj_contraste'], "text" ),
  15.                        GetSQLValueString($_POST['obj_luminosite'], "text" ),
  16.                        GetSQLValueString($_POST['obj_resolution'], "text" ),
  17.                        GetSQLValueString($_POST['obj_angle'], "text" ),
  18.                        GetSQLValueString($_POST['obj_operateur'], "text" ),
  19.                        GetSQLValueString($_POST['obj_caracteristique'], "text" ),
  20.                        GetSQLValueString($_POST['obj_puissance'], "text" ),
  21.                        GetSQLValueString($_POST['obj_chargeurcd'], "text" ),
  22.                        GetSQLValueString($_POST['obj_cassette'], "text" ),
  23.                        GetSQLValueString($_POST['obj_tuner'], "text" ),
  24.                        GetSQLValueString($_POST['obj_GEQ'], "text" ),
  25.                        GetSQLValueString($_POST['obj_enregistreur'], "text" ),
  26.                        GetSQLValueString($_POST['obj_disquedur'], "text" ),
  27.                        GetSQLValueString($_POST['obj_gravure'], "text" ),
  28.                        GetSQLValueString($_POST['obj_lecture'], "text" ),
  29.                        GetSQLValueString($_POST['obj_mar_numero'], "int" ),
  30.                        GetSQLValueString($_POST['obj_numero'], "int" ));
  31.   mysql_select_db($database_off_connexion, $off_connexion);
  32.   $Result1 = mysql_query($updateSQL, $off_connexion) or die(mysql_error());
  33.   $updateGoTo = "voir_offres.php";
  34.   if (isset($_SERVER['QUERY_STRING'])) {
  35.     $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
  36.     $updateGoTo .= $_SERVER['QUERY_STRING'];
  37.   }
  38.   header(sprintf("Location: %s", $updateGoTo));
  39. }


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  PHP

  Prob upload & unlink

 

Sujets relatifs
Formulaire upload fichier = mauvais dossier [resolu]Prob installation Flash player 9.0 Debug
Prob de lancement d'une requeteProb avec swfObject
plusieurs ligne d'upload de fichier, identifier celle choisiProb loadmovie débutant
upload des images[PHP] Upload par fichier le retour !
Upload d'image fonctionnel mais différéProb .csv
Plus de sujets relatifs à : Prob upload & unlink


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR