www.webdeveloper.com
Results 1 to 2 of 2

Thread: php image count but when deleting image have count problem

  1. #1
    Join Date
    Jun 2014
    Posts
    6

    Unhappy php image count but when deleting image have count problem

    Hi all,

    i have an upload system that gives an id to the uploaded image ex. 159-1.jpg

    When another image is uploaded it continues to count 159-2, -3 and so fort

    But when i delete (unlink) an image within the page at random order there is a count problem ex below

    159-1.jpg
    159-2.jpg - deleting from server
    159-3.jpg

    what happens is the file ex 159-3.jpg gets moved up and is renamed as 159-2.jpg so when you try to delete (unlink) the file it try's to delete the 159-2.jpg who was deleted just before and who should be the file 159-3.jpg.

    Does anyone have a good solution?

    PHP Code:
    <?php
            
                
    for ($i=1$i <= $countpic+1$i++)
                {
                    echo 
    "<tr>";
                        echo 
    "<td>";
                            if (
    $i == $countpic+1){
                                echo 
    "<img src='../img/img_liste_vierge.png' width='234' height='176'/>";
                            }else{
                                echo 
    "<img src='"."../img/annonce/".$pathImg."/".substr($_GET['id'], 01)."/".$_GET['id']."-".$i.".jpg' width='234' height='176'/>";
                            }
                        echo 
    "</td>";
                        echo 
    "<td style='vertical-align:middle; text-align:center'>";
                            echo 
    "  <div id='photo_upload".$i."' style='float:left; height:190px; width:296px;background:no-repeat !important;background-size:190px !important;'></div>";
                        echo 
    "</td>";
                        echo 
    "<td style='vertical-align:middle; text-align:center'>";
                            echo 
    "  <form id='uploadform".$i."' class='".$i."' method='post'
                                    enctype='multipart/form-data'
                                    action='fonction/image-upload.php'>
                                    <input type='hidden' value='"
    .$i."' name='i'/>
                                    <div class='fileinputs'>
                                        <input name='file' class='file' id='file' size='27' type='file' />
                                    </div>    
                                    <div id='uploadbtn"
    .$i."' class='div_bouton texte_bg_bleu' style='width:70px;margin-bottom:5px'>Charger</div>
                                    <iframe id='target_iframe"
    .$i."' name='target_iframe' src='' style='width:0;height:0;border:0px'></iframe>
                                    </form>
                                    <input type='hidden' id='src1"
    .$i."' value='img/annonce/".$pathImg."/".substr($_GET['id'], 01)."/".$_GET['id']."-".$i.".jpg' />
                                    <input type='hidden' id='src2"
    .$i."' value='' />
                                    <div id='valider"
    .$i."' alt='".$i."' class='div_bouton texte_bg_violet' style='width:70px;display:none'>Valider</div>";
                        echo 
    "</td>";
                        echo 
    "<td align='center'>";
                            if (
    $i==1){
                                echo 
    "La photo principale ne peut être que modifiée.";
                            }elseif (
    $i==$countpic) {
                                echo 
    "<a href='annonce_modifier2.php?image=suppression&id=".$_GET['id']."&t=".$_GET['t']."&pic=".$i."'><img src='../img/poubelle.png' width='30' height='30'/></a>";
                            }else{
                                echo 
    "<a href='annonce_modifier2.php?image=suppression&id=".$_GET['id']."&t=".$_GET['t']."&pic=".$i."'><img src='../img/poubelle.png' width='30' height='30'/></a>";
                            }
                        echo 
    "</td>";
                    echo 
    "</tr>";    
                }
                
    closedir($dirpic);
            
    ?>
    Image exemple
    http://www.particimmo.com/delete-images-file.jpg

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,432
    Well, my eyes go blurry trying to read what's going on in all that HTML, but my guess is I'd get rid of using a for() loop, and instead build an array of image file names via glob(), then do a foreach() loop on that array, instead.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles