Deleting images
Posted: Mon Dec 29, 2008 11:04 am
I wrote this function about a day ago (I just started to learn php only 4 days ago...so go easy on me =P ). Basicall, right now this script simply scans a folder, then posts all the images it finds between li tags. What I would like to do is write another function (to be used on a seperate page) that would add checkboxes with a delete button or something to that affect that would allow deletion of a single image or of multiple images (hence why I thought a check mark system would be best).
I understand using unlink to delete the images, but I'm still lost at the point of printing a checkbox for each image still.
Also, on a side note. This script is setup because I have another script that when you upload an image, it creates a thumbnail of it as well and stores it in a seperate folder. This script actually finds all of the thumbnails, then populates the page with those, and links each image to their respective full sized image. Hope that makes sense =)
I understand using unlink to delete the images, but I'm still lost at the point of printing a checkbox for each image still.
Also, on a side note. This script is setup because I have another script that when you upload an image, it creates a thumbnail of it as well and stores it in a seperate folder. This script actually finds all of the thumbnails, then populates the page with those, and links each image to their respective full sized image. Hope that makes sense =)
Code: Select all
<?php
function pagepop(){
$imglist = scandir("images/thumb_nails");
$arr = array($imglist);
$length = count($imglist);
for($x=2; $x<$length; $x++){
foreach($arr as $image){
$path_to_thumb = 'images/thumb_nails/' . $image[$x];
$path_to_full = 'images/full_sized/' . $image[$x];
// list of approved file extensions
$approved = array (
'gif' => "image/gif",
'jpg' => "image/jpeg",
'jpeg' => "image/jpeg",
'png' => "image/png"
);
$ext = pathinfo($image[$x]);
if(array_key_exists($ext['extension'], $approved)){
echo "<li class =\"thumb_li\"><a href =\"$path_to_full\" id=\"remove\"><img src=\"$path_to_thumb\" class=\"thumbnail\" /></a></li>";
}
}
}
}
?>