note 103188 rejected from faq.using by danbrown
| From: | danbrown@php.net | Date: | Wed, 30 Mar 2011 19:41:22 +0000 |
| Subject: | note 103188 rejected from faq.using by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-178360@lists.php.net to get a copy of this message | ||
Note Submitter: qakbar at hotmail dot co dot uk
----
I'm new to pho and need some help. I have a php script that deletes thumbnail images in a given
folder using the unlink function. But I wanted to know if their was a way to delete the large
images in the main images folder and also to put in messages to state which image has been unlinked
or if no image has been slected to delete. my code is as below. <?php// directory
separatordefined("DS")|| define("DS", DIRECTORY_SEPARATOR); // root
pathdefined("ROOT_PATH")|| define("ROOT_PATH", realpath(dirname(__FILE__))); //
upload folder directorydefined("UPLOAD_DIR")|| define("UPLOAD_DIR",
"../imagefolder/thumbfolder"); // path to the upload
folderdefined("UPLOAD_PATH")|| define("UPLOAD_PATH", ROOT_PATH.DS.UPLOAD_DIR);
function getAllFiles($folder = null) {if(!empty($folder) && is_dir($folder)) {if($handle =
opendir($folder)) {$out = array();while($file = readdir($handle)) {if(is_file($folder.DS.$file))
{$out[] = $file;}}closedir($handle);return $out;}return false;}return false;} $files =
getAllFiles(UPLOAD_PATH); if (!empty($_POST['file'])) {foreach($_POST['file'] as
$file) {unlink(UPLOAD_PATH.DS.$file) or die("Failed to <strong
class='highlight'>delete</strong> file");}header("location: " .
$_SERVER['REQUEST_URI']);}?> <?php if (!empty($files)) { ?> <form
name="form1" method="post"><?php foreach($files as $key => $file) {
?><label for="file_<?php echo $key; ?>"><input type="checkbox"
name="file[]" id="file_<?php echo $key; ?>" value="<?php echo
$file; ?>" /> <img src=<?php echo UPLOAD_DIR.DS.$file; ?>
/></label><?php } ?><input type="submit" name="delete"
value="Delete" /></form> <?php } ?> Thank you