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
https://forums.phpfreaks.com/topic/85939-unlink-form-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.