Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8370279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:52:40+00:00 2026-06-09T13:52:40+00:00

I am working on a PHP Gallery application, and need some help here. Actually

  • 0

I am working on a PHP Gallery application, and need some help here. Actually I have a page where images from a specific directory are displayed directly. With each one of the images displayed there is a dynamically generated submit button that will be used to delete respective images separately.

Every image has its own submit button, that will be used to delete that image. Being new to php I need some method that can be called to delete only that image from the actual or physical directory.

There is a similarity between image and button that I have coded it such that every image and its respective button has names such as “img_1” and its button is “del_1”.

<form id="albumGallery" name="albumGallery" method="POST">
<?php

   $dir =  htmlspecialchars($_GET["p"]) . "/";
    $imgs = array();

    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
        if (!is_dir($file) && preg_match("/\.(bmp|jpe?g|gif|png)$/", $file)) {
            array_push($imgs, $file);
        }
    }

    closedir($dh);
} else {
    die('cannot open ' . $dir);
}
$i=0;
echo "<div id='images'>";
foreach ($imgs as $idx=>$img) {
    //$class = ($idx == count($imgs) - 1 ? ' class="last"' : '');
    echo '<table style="float: left; border: 1px solid #EFEFEF; border-radius: 5px; padding: 5px; margin: 5px;"><tr><td><a href="'. $dir . $img .'" rel="example_group" ><img src="' . $dir . $img . '" alt="' . $img . '" id="'. "img_" . $i .'"/>
    </a></td></tr><tr><td><input type="submit" class="ctrlDelete" value="" id="'. "del_" . $i .'"/></td></tr></table>';
    $i++;
}
  echo "</div>";
  ?></form>

So, I need to make a method so that each button deletes its respective image and the form is posted back to self.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:52:42+00:00Added an answer on June 9, 2026 at 1:52 pm

    For your issue, it is better to use anchors. You can style them as pseudo-buttons, if you want. Then just generate links like delete.php?id=23, which will execute the appropriate deletion script with $_GET argument passed.

    Below is the very simple implementation:

    <table>
    
        <tr>
            <td>Title</td>
            <td>Image</td>
            <td>Actions</td>
        <tr>
    
        <?php
    
        foreach ($table as $row)
        {
            echo "<tr>";
            echo "<td>".$row['title']."</td>";
            echo "<td>".$row['image']."</td>";
            echo "<td>";
            echo "<a href='delete.php?id=".$row['id']."'>Delete</a>";
            echo "<a href='edit.php?id=".$row['id']."'>Edit</a>";
            echo "</td>";
            echo "</tr>";
        }
    
        ?>
    
    </table>
    

    delete.php and edit.php should contain the following code at the very end:

    <?php
    
    header("Location: http://www.example.com/");
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a problem, i'm working on a gallery php script and need help,
I am working with php and want to have a page that has a
I am trying to replace some main images with images from a gallery. Everything
I have been working on an image gallery in PHP and Javscript for a
I'm working on an image gallery, and I have some problems with aligning of
i have a jcarousel gallery of images but the jcarousel is not working at
I have a gallery page I am working on and cannot seem to get
I am currently working on this website , and i need some help regarding
We currently have a working php mail script, this works fine and as we
Working with PHP Xpath trying to quickly pull certain links within a html page.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.