Help with arrays in PHP
Hi All,
I have created a page that shows thumbnail images of all images in a
given directory. Here is the function that searches the directory and
builds an array of qualified files:
> function getImages($dir) {
> $directory = new DirectoryIterator($dir);
> $fileTypes = '#\.jpg$|\.jpeg$|\.gif$|\.png$|\.JPG$|\.GIF$|\.PNG $#i';
> $filtered = new RegexIterator($directory, $fileTypes);
> $array = array();
> foreach ($filtered as $item) {
> $array[] = $item->getFilename();
> }
> return new ArrayIterator($array);
> }
>
> // get an ArrayIterator of filenames and the total number:
> $images = getImages('../images/images_news/');
> $totalImages = $images->count();
Here is the HTML and PHP used to display the images (I'm excluding code
that is specific to the paging function):
> // Implement offset and files per page
> foreach (new LimitIterator($images, $offset, $filesperpage) as
> $image) { ?>
> <div class="imgcont">
> <div class="imgholder">
> <img src="../images/images_news/<?php echo $image; ?>"
> alt="<?php echo $image; ?>" height="55" class="center" />
> </div>
> <p class="smallname"><?php echo $image; ?></p><br />
> </div>
> <?php } ?>
> <div class="clear"><br />
My question is this. I need to provide a way to delete images that will
no longer be needed. Actually, I need to be able to delete the main
image and the thumbnail image, each of which is in a separate
directory. What I don't know is how this type of thing is normally done
(I don't want the FTP route because I don't want a client messing about
in the directory structure). And what I don't understand is how to
select one or more files to delete when they were produced by an array.
For ease of use, it would be nice if I could add a checkbox that the
user could check to indicate that the image(s) should be deleted. I
just can't figure out how to select the file(s). I sure hope this is
not one of those simple things that will make me hide my head in shame.
Any help would be most appreciated.
Brett
|