Jump to content

PHP delete with checkboxes


MHovet

Recommended Posts

Hello,

 

Kinda new to this site, but I need help.

 

I have a page that can view all the files in a directory on my server but I can not get it to delete selected files with checkboxes.

 

Anyway here is my code, any help is appreciated.

 

<?php

session_start();
if($_SESSION['user-agent'] != $_SERVER['HTTP_USER_AGENT']){
die ("noauth");
}
if($_SESSION['auth']!=1){
die ("noauth");
}


require_once($_SERVER['DOCUMENT_ROOT'].'/pagestructure/common_noauth.php5');
require_once($_SERVER['DOCUMENT_ROOT'].'/db/dbc.php5');
require_once('dbost.php5');
?>

<!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" xml:lang="en" lang="en">
<head>
<title>FiST</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../css/fnp3.css" />
<link rel="stylesheet" type="text/css" href="../css/fist.css" />
<script language="Javascript" type="text/javascript" src="../pagestructure/bbox.js"></script>
</head>
<body>

<?php
echo DoHeader(1); 
echo DoContainerTopLid(1);


?>
<div class="ContainerContents">
	<?php  //Since this file is part of a web application, verify permission for that application.
	if($_SESSION['FIST']==''){
		echo '<p>FiST is not an application that you have permission to use.</p>'.PHP_EOL;
	}
	else {  //Show the application.
		?>
		<div id="applicationHeader">
			<?php require('fist_header.php5'); ?>
		</div>

		<div id="applicationInterface">
			<div class="BBoxFt">
				<?php echo table_list($_SESSION['FIST']); ?>
			</div>
			<div class="BBox">
					<div class="BBoxBd">
						<form>			
						<?php
						$dir = opendir('uploads/');
						echo '<ul>';
						while ($read = readdir($dir)){
							if ($read!='.' && $read!='..'){
								echo '<li><a href="uploads/'.$read.'" target="_blank">'.$read.' </a>';
								echo ' (<input type="checkbox" name="Del" value='.$read.' />Delete)';
							}

						}
						echo '<br /><br />';
						echo '<a href="download.php5">Delete Selected Files</a>';
						echo '</ul>';
						closedir($dir);
						?>	
						</form>

					</div>
			</div>

		</div><!-- end AppInterface -->
		<div id="applicationFooter">
			<?php require('fist_footer.php5'); ?>
		</div>
		<?php
		}
		?>
	</div><!-- end container contents -->
	<?php
	echo DoContainerBottomLid(1);
	echo DoFooter(1);
	?>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/195494-php-delete-with-checkboxes/
Share on other sites

If you're using a form to diplay the checkboxes, why aren't you using a submit button so when you get the $_POST from the button, you can unset all the files by the $_POST['Del']

 

if(isset($_POST['submit'])) {
        foreach($_POST['Del'] as $del) {
               //code to unset the files
        }
}

 

Haven't tested it but the thoery is there

Thanks for the reply, I am kind of a newbie to php.

 

So I inserted the code you posted and I just get redirected back to the original page when I click on it.

 

I think I need a different button that points to the unset command. but I am not sure how to do that.

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.