|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
unlink function for multiple files
I am looking for a way to unlink files with a check box for multiple files. Users upload files, then need a way to unlink them, to clear up old newsletters.
I display the files, then follow each file with a check box, but I'm lost as how to process the box to loop through an unlink function. If anyone has seen such a script, please point me in the right direction.
__________________
bow wow! |
|
#2
|
||||
|
||||
|
I'd say, give each checkbox a name that can be traced back to the filename, and cycle through the $_POST[] array, filtering out things that aren't checkboxes.
|
|
#3
|
|||
|
|||
|
Here is a sample of what you can do... I supplied you with enough code to test this puppy out... you will need to write the functionality that iterates through the associative array and delete each file:
Code:
<?php
if (isset($_POST['delete']) && $_POST['delete']=='yes') {
print '<pre>';
print_r($_POST['checkbox']);
print '</pre>';
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=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form name="form1" id="form1" method="post" action="">
<input type="hidden" name="delete" value="yes" />
<p>
<input name="checkbox[file1.jpg]" type="checkbox" id="checkbox[file1.jpg]" value="checkbox" />
file1</p>
<p>
<input name="checkbox[file2.jpg]" type="checkbox" id="checkbox[file2.jpg]" value="checkbox" />
file 2</p>
<p>
<input name="checkbox[file3.jpg]" type="checkbox" id="checkbox[file3.jpg]" value="checkbox" />
file 3
</p>
<input type="submit">
</form>
</body>
</html>
__________________
__________________________________________________ _ Wil Moore III, MCP | Integrations Specialist | Senior Consultant Are You Listed...? | DigitallySmooth Inc. |
|
#4
|
|||
|
|||
|
As a side note, what the above code does is the following:
1 - The form has checkboxes which act as an associative array when sent to the php script. 'checkbox'. In each of the array indexes you have the name of the file such as 'file1.jpg'. 2 - The script finds that you would like to process the delete functionality and just loops through the indexes of the checkbox array which is actually inside the $_POST array. (superglobal array). |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > unlink function for multiple files |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|