How to display images for delete
I have the following code that deletes the images from a folder but it does not display the images on the page and also whats worse is that it display all folder and files within the given folder.
I only want the images to be deleted not any folders with the given folder name.
my code is:
<?php
$path = "../imagefolder";
if(isset($_POST['file']) && is_array($_POST['file']))
{
foreach($_POST['file'] as $file)
{
unlink($path . "/" . $file) or die("Failed to <strong class='highlight'>delete</strong> file");
}
header("location: 开发者_如何转开发" . $_SERVER['REQUEST_URI']); //redirect after deleting files so the user can refresh without that resending post info message
}
?>
<form name="form1" method="post">
<?php
$path = "../imagefolder";
$dir_handle = @opendir($path) or die("Unable to open folder");
while (false !== ($file = readdir($dir_handle)))
{
if($file == "index.php")
continue;
if($file == ".")
continue;
if($file == "..")
continue;
echo "<input type='CHECKBOX' name='file[]' value='$file'>";
echo "<img src='$file' alt='$file'><br />";
}
closedir($dir_handle);
?>
<input type="submit" name="Delete" value="Delete">
</form>
This is the code that displays my gallery
<?php
function createLbFromDir ($linkname, $galname, $directory, $thumbdirectory, $extensions = array ('jpg', 'jpeg','png','gif')) {
$gallery = "";
$dh = opendir ($directory);
while ($file = readdir ($dh)) {
$parts = explode(".", basename ($file));
$extension = $parts[count($parts)-1];
if (!is_dir ($directory . $file) && ($file != ".." && $file != ".") && in_array($extension, $extensions)) {
$gallery.= "<a href="".$directory.$file."" rel="lightbox[".$galname."]"><img src="".$thumbdirectory.$file."" alt=""></a>n";
}
}
return $gallery;
}
// Page variables
$pageTitle = "SAFAAS - Asian Clothes Specialists";
$currentPage = "gallery";
require_once("includes/header.php");
require_once("includes/menu.php");
?>
<div id="portfolio_content" class="block">
<ul>
<?php echo createLbFromDir ("Linkname", "galleryname", "imagefolder/" , "imagefolder/thumbfolder/"); ?>
</ul>
</div>
The images are displayed for the gallery fine and the gallery works and uses the lightbox slider plugin and works fine.
I just need the images to display on my deleteimages.php page and only images are shown not subfolders within the folder.
Change this
while (false !== ($file = readdir($dir_handle)))
to
while (false != ($file = readdir($dir_handle)))
This section of your code:
$echo "<img src='$file' alt='$file'><br />";$
should be:
$echo "<img src='$path$file' alt='$file'><br />";$
that should fix it :)
精彩评论