Upload image php probleme!!!

Résolu
bretonm2004 Messages postés 320 Date d'inscription   Statut Membre Dernière intervention   -  
jjsteing Messages postés 1613 Date d'inscription   Statut Contributeur Dernière intervention   -
Bonjour,

j'ai un script d'upload d'image en php qui fonctionne tres bien seul hic si la personne n'upload pas d'image ca fait un carré blanc avec un x en haut j'aimerait qu'a la place ce soit une image qui est marqué pas d'image

voici mon script

<?php
//connection a la base de données
mysql_connect('localhost', 'xxxx', 'xxxxxxxxx');
mysql_select_db("auto7837_auto");

//récupération des variables du formulaire
if(isset($_POST['envoyer'])) {
$typedannonce=$_POST['typedannonce'];
$marque=$_POST['marque'];
$autres=$_POST['autres'];
$modele=$_POST['modele'];
if($_POST['prix'] == null){
$prix = "S/O";
} else {
$prix = $_POST['prix'];
}
$negociable=$_POST['negociable'];
$annee=$_POST['annee'];
$etat=$_POST['etat'];
if($_POST['carburant'] == null){
$carburant = "S/O";
} else {
$carburant = $_POST['carburant'];
}
if($_POST['kilometrage'] == null){
$kilometrage = "S/O";
} else {
$kilometrage = $_POST['kilometrage'];
}
if($_POST['transmission'] == null){
$transmission = "S/O";
} else {
$transmission = $_POST['transmission'];
}
$immatricule=$_POST['immatricule'];
if($_POST['climatisation'] == null){
$climatisation = "S/O";
} else {
$climatisation = $_POST['climatisation'];
}
if($_POST['audio'] == null){
$audio = "S/O";
} else {
$audio = $_POST['audio'];
}
if($_POST['cylindre'] == null){
$cylindre = "S/O";
} else {
$cylindre = $_POST['cylindre'];
}
if($_POST['puissance'] == null){
$puissance = "S/O";
} else {
$puissance = $_POST['puissance'];
}
if($_POST['consommation'] == null){
$consommation = "S/O";
} else {
$consommation = $_POST['consommation'];
}
if($_POST['couleurinterieure'] == null){
$couleurinterieure = "S/O";
} else {
$couleurinterieure = $_POST['couleurinterieure'];
}
if($_POST['couleurexterieure'] == null){
$couleurexterieure = "S/O";
} else {
$couleurexterieure = $_POST['couleurexterieure'];
}
if($_POST['telephone'] == null){
$telephone = "S/O";
} else {
$telephone = $_POST['telephone'];
}
$email=$_POST['email'];
$message=$_POST['message'];
$date= date('d-m-Y');
$i=0; $v=0; for($j=0; $j<7; $j++) { $image[$j]=''; $fn[$j]=''; }
if(!empty($_FILES['image1']['tmp_name'])) { $image[$i]=$_FILES['image1']; $i++; }
if(!empty($_FILES['image2']['tmp_name'])) { $image[$i]=$_FILES['image2']; $i++; }
if(!empty($_FILES['image3']['tmp_name'])) { $image[$i]=$_FILES['image3']; $i++; }
if(!empty($_FILES['image4']['tmp_name'])) { $image[$i]=$_FILES['image4']; $i++; }
if(!empty($_FILES['image5']['tmp_name'])) { $image[$i]=$_FILES['image5']; $i++; }
//INSERTION DE la requête sql
$sql='INSERT INTO avendrenonpubliee(id, typedannonce, marque, autres, modele, prix, negociable, annee, etat, carburant, kilometrage, transmission, immatricule, climatisation, audio, cylindre, puissance, consommation, couleurinterieure, couleurexterieure, telephone, email, message, date, image1, image2, image3, image4, image5) VALUES("","'.$typedannonce.'","'.$marque.'","'.$autres.'","'.$modele.'","'.$prix.'","'.$negociable.'","'.$annee.'","'.$etat.'","'.$carburant.'","'.$kilometrage.'","'.$transmission.'","'.$immatricule.'","'.$climatisation.'","'.$audio.'","'.$cylindre.'","'.$puissance.'","'.$consommation.'","'.$couleurinterieure.'","'.$couleurexterieure.'","'.$telephone.'","'.$email.'","'.$message.'","'.$date.'","'.$fn[0].'","'.$fn[1].'","'.$fn[2].'","'.$fn[3].'","'.$fn[4].'")';
mysql_query($sql) or die(mysql_error());
$idinsert=mysql_insert_id();
//AJOUT DES IMAGES
for($j=0; $j<$i; $j++) {
list($width, $height, $type, $attr)=getimagesize($image[$j]['tmp_name']);
if($image[$j]['size']>524288 && !$image[$j]['error'])
exit('Le fichier ne doit pas depasser 500 ko');
if(empty($error)) {
if(move_uploaded_file($image[$j]['tmp_name'], '/home/auto7837/public_html/photos/avendrenp/'.$idinsert.'-'.$v.'.jpg')) {
$fn[$v]=$idinsert.'-'.$v.'.jpg';
$v++;
}
unset($image[$j]['tmp_name']);
}
}
// on modifie les images sur la requete
mysql_query('UPDATE avendrenonpubliee SET image1="'.$fn[0].'", image2="'.$fn[1].'", image3="'.$fn[2].'", image4="'.$fn[3].'", image5="'.$fn[4].'" WHERE id="'.$idinsert.'"'); ?>

1 réponse

  1. jjsteing Messages postés 1613 Date d'inscription   Statut Contributeur Dernière intervention   181
     
    Bonsoir,

    Cré une image où tu marque 'pas d image', que tu apelle par ex sansimage.jpg.

    Dans la page où tu affiche l image, met se code :

    if fileexist('lelienverstonimage){
    <img src='lelienverstonimage'>
    }else{
    <img src='sansimage.jpg'>
    }
    -1
    1. bretonm2004 Messages postés 320 Date d'inscription   Statut Membre Dernière intervention   2
       
      ca ne fonctionne pas

      voici le code que j ai fait

      echo "<tr>
      <td width='114'>
      <center>
      if fileexist('photos/avendrenp/".$row['image1']." '){
      <a href='afficheralouer.php?id=$id' alt='Voir image en grand'>
      <img src=''photos/avendrenp/".$row['image1']." ''>
      </a>
      }else{
      <img src='images/bouton.gif'>
      }
      </center></td>
      <td width='258' height='78'>".$row['marque']." ".$row['autres']." ".$row['modele']." ".$row['annee']." ".$row['negociable']."</td>
      <td align='center' width='147'>".$row['prix']." FCFA</td>
      <td align='center' width='153'>".$row['date']."</td>
      </tr>";

      ca me marque ca avec les photos entre les parenteses

      if fileexist('photos/avendrenp/26-0.jpg '){ }else{ }
      0
    2. bretonm2004 Messages postés 320 Date d'inscription   Statut Membre Dernière intervention   2
       
      la commande fileexist n existe pas c est file_exists

      voici je me suis monté un code comme ca a la place

      if ($row['image1'] == NULL){ echo"<tr> <td width='75' height='78'>
      <a href='afficheralouer.php?id=$id' alt='Voir image en grand'>
      <img src='images/bouton.gif'>
      </a>
      </td>";}
      else{echo " <td width='75' height='78'>
      <a href='afficheralouer.php?id=$id' alt='Voir image en grand'>
      <img src='photos/alouernp/".$row['image1']." ' width='75' />
      </a>
      </td>";}
      echo "
      <td width='258' height='78'>".$row['marque']." ".$row['autres']." ".$row['modele']." ".$row['annee']." ".$row['negociable']."</td>
      <td align='center' width='147'>".$row['prix']." FCFA</td>
      <td align='center' width='153'>".$row['date']."</td>
      </tr>";

      }

      et ca fonctionne impec
      0
    3. jjsteing Messages postés 1613 Date d'inscription   Statut Contributeur Dernière intervention   181
       
      Oups, désolé pour la faute d orthographe ;)
      0