SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
-
Mar 9, 2006, 01:58 #1
- Join Date
- Mar 2004
- Location
- Fort Lauderdale
- Posts
- 522
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
deleting file - without knowing its ext
Hi,
I have a directory with files:
Code:images/articles/temp article_username_image1.gif article_username_image2.jpg article_username_image_graphics.jpg
Code:images/articles/temp/thumb article_username_image1_thumb.jpg article_username_image1_thumb.gif
Since I store two versions of the image. First in the temp directory and second in the thumb directory - how do I delete them both upon finding out the checkbox selected is to delete image1
This is what I have, but I have to repeat the same code for all images that I want to delete. Is there a better version:
PHP Code:if ( $_REQUEST['deleteImage1'] ) {
$image_='image1';
foreach ( glob( "$searchArticleDir*" ) as $filename ) {
list($article_, $username_, $image_num, $ext_)= split('[_.]', basename($filename));
if ( $image_num == $image_ ) {
$full_path= $tempArticlePath . basename( $filename );
unlink( $full_path );
$bodytag = str_replace("temp", "temp/thumb", "$full_path");
$bodytag2 = str_replace($image_, $image_."_thumb", "$bodytag");
unlink( $bodytag2 );
}
}
}
is there a better way to do this? I have a max of 4 images that can be deleted at once...
-
Mar 9, 2006, 03:14 #2
- Join Date
- Mar 2006
- Posts
- 6,132
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
im kinda sleepy, but im not seeing why your reading all the files in the directory
functions are nice when you need to repeat an operation, so you dont have to write it out over and over
PHP Code:<?php
function delete_images($image_num) {
$path = 'images/articles/temp';
unlink("$path/$image_num.gif");
unlink("$path/$image_num.jpg");
unlink("$path/thumb/$image_num" . "_thumb.gif");
unlink("$path/thumb/$image_num" . "_thumb.jpg");
}
if (isset($_REQUEST['deleteImage1'])) {
delete_images('image1');
}
if (isset($_REQUEST['deleteImage2'])) {
delete_images('image2');
}
?>
PHP Code:if (isset($_REQUEST['deleteImage1'])) {
delete_images('image1');
}
-
Mar 9, 2006, 17:12 #3
- Join Date
- Mar 2004
- Location
- Fort Lauderdale
- Posts
- 522
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
LOL -you are right. What was I thinking???
Bookmarks