Jump to content
xisto Community

Drakos33

Members
  • Content Count

    2
  • Joined

  • Last visited

Posts posted by Drakos33


  1. Hi Guys

    I have read through your forum and it has been so helpful thanx so much however I am stuck now and I will apreciate some help plaese. I have tried to construct the "checkbox" form in order to display and/or delete uploaded mp3 files.

    When I click the Delete btn the page only refreshes and the file does not get deleted as its still displayed on the refreshed list and still lying in the dir.

    Can someone please tell me what I'm doing wrong?

    Thanx in advance:

     

    <?phpif(isset($_POST[$file])){$checkbox = $_POST[$file];if($checkbox == on) { //checkbox is selectedunlink($file);if(!unlink($file)) die("Failed to delete file");}}$dir = opendir("./$id/");while (false !== ($file = readdir($dir))) {if (strpos($file, '.MP3',1)) {echo '<html><form method="post">';echo "{$file}<input type=CHECKBOX name=$file>";echo '<input type="submit" name="submit" value="Delete" /><br />';echo '</form>';}}?>

     

     

    I would use file name as check box identifier. So first, we will add checkbox in your code

    <?php$path = "./";$dir_handle = @opendir($path) or die("Unable to open folder");while (false !== ($file = readdir($dir_handle))) {if($file == "index.php")continue;if($file == ".")continue;if($file == "..")continue;echo "<input type=CHECKBOX name=$file>";echo "<img src='$file' alt='$file'><br />";}closedir($dir_handle);?>
    That is, now you have images with check box beside them. In order to delete the chosen images, you need to capture which checkbox is selected.

    This is the example of how to know which check box is checked (assuming, you are using POST method to submit the form using delete button):

     

    <?php$path = "./";$dir_handle = @opendir($path) or die("Unable to open folder");//We list the name of the files again, since the name of the checkbox is the same with the name of the filewhile (false !== ($file = readdir($dir_handle))) {if($file == "index.php")continue;if($file == ".")continue;if($file == "..")continue;if(isset($_POST[$file])){$checkbox = $_POST[$file];if($checkbox == on) { //checkbox is selected//Delete the fileif(!unlink($file)) die("Failed to delete file");}}?>
    Hopefully it helps tongue.gif

     


  2. Hi GuysI have read through your forum and it has been so helpful thanx so much however I am stuck now and I will apreciate some help plaese. I have tried to construct the "checkbox" form in order to display and/or delete uploaded mp3 files.When I click the Delete btn the page only refreshes and the file does not get deleted as its still displayed on the refreshed list and still lying in the dir.Can someone please tell me what I'm doing wrong?Thanx in advance:

    <?phpif(isset($_POST[$file])){$checkbox = $_POST[$file];if($checkbox == on) { //checkbox is selectedunlink($file);if(!unlink($file)) die("Failed to delete file");}}$dir = opendir("./$id/");while (false !== ($file = readdir($dir))) {if (strpos($file, '.MP3',1)) {echo '<html><form method="post">';echo "{$file}<input type=CHECKBOX name=$file>";echo '<input type="submit" name="submit" value="Delete" /><br />';echo '</form>';}}?>
×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.