Jump to content

Unlink Form Help...


JsusSalv

Recommended Posts

Hello:

 

I have gone through the help files and am still in need of help.  All I need is to create a simple XHTML form that scans a directory, shows the files (all will be image files), and adds a checkbox that allows users to delete a particular file.  Ideally, an "Are you sure you want to delete this file" message should appear/popup followed by a file deletion confirmation.  Below is my code for the form:

 

<?php

$webAddr = "http://www.xxxx.xxx/xx";

 

$dir = "/path/to/directory/where/the/Images/are/located/";

if(($dirfiles = scandir($dir))!==false) {

    foreach($dirfiles as $imgfile) {

      if($imgfile != '.' && $imgfile != '..')

  echo "<img src=\"$webAddr/Images/$imgfile\" title=\"$imgfile\" alt=\"$imgfile\" />";

 

  if (isset($_POST['delete']) && $_POST['delete']=='yes') {

    print 'Image is being deleted...';

    exit;

  }

}

}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

</head>

 

<body>

<form name="form1" id="form1" method="post" action="delete_image_file.php">

<input type="hidden" name="delete" value="yes" />

  <p>

    <input name="checkbox[<?php echo $imgfile; ?>]" type="checkbox" id="checkbox[<?php echo $imgfile; ?>]" value="checkbox" />

  <?php echo $imgfile; ?></p>

<input type="submit" value="Delete Image">

</form>

</body>

</html>

 

 

 

For the file, delete_image_file.php, that should process the form:

<?php

$dir = "/path/to/directory/where/the/Images/are/located/";

if(($dirfiles = scandir($dir))!==false) {   

    foreach($dirfiles as $imgfile) {

      if($imgfile != '.' && $imgfile != '..')

  if (unlink('/path/to/directory/where/the/Images/are/located/' . $imgfile)) {

      print "The file $imgfile has been deleted!\n";

  } else {

      print "Deletion of $imgfile failed!\n";

  }

    }

}

?>

 

 

 

I am having much difficulty figuring out what goes where.  Anyhow, if you have some info you'd like to share then please add example scripts.  I don't need posts that tell me what I should or shouldn't do.  That isn't productive for me.  Thank you everyone!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.