note 103184 added to function.unlink

From: Date: Wed, 30 Mar 2011 18:07:19 +0000
Subject: note 103184 added to function.unlink
Groups: php.notes 
Request: Send a blank email to php-notes+get-178349@lists.php.net to get a copy of this message
I'm new to php 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 separator defined("DS") || define("DS", DIRECTORY_SEPARATOR); // root path defined("ROOT_PATH") || define("ROOT_PATH", realpath(dirname(__FILE__))); // upload folder directory defined("UPLOAD_DIR") || define("UPLOAD_DIR", "../imagefolder/thumbfolder"); // path to the upload folder defined("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 ---- Server IP: 87.124.126.105 Probable Submitter: 91.110.182.57 (proxied: 91.110.182.57) ---- Manual Page -- http://www.php.net/manual/en/function.unlink.php Edit -- https://master.php.net/note/edit/103184 Del: integrated -- https://master.php.net/note/delete/103184/integrated Del: useless -- https://master.php.net/note/delete/103184/useless Del: bad code -- https://master.php.net/note/delete/103184/bad+code Del: spam -- https://master.php.net/note/delete/103184/spam Del: non-english -- https://master.php.net/note/delete/103184/non-english Del: in docs -- https://master.php.net/note/delete/103184/in+docs Del: other reasons-- https://master.php.net/note/delete/103184 Reject -- https://master.php.net/note/reject/103184 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#178349) next »