Lifelesspeople.com

 Forum FAQsForum FAQs  Knowledge BaseKnowledge Base  RulesRules   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   HostingHosting   RegisterRegister 
 DonateDonate   WikiWiki   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

deleting a file using php

 
Lifelesspeople.com Forum Index -> Web Architects' Abode
Post new topic   Reply to topic View previous topic :: View next topic  
Author Message
Desbrina
Jadeite


Joined: 11 Jun 2005
Posts: 2958
Location: Earth

PostPosted: Wed Oct 17, 2007 4:26 am    Post subject: deleting a file using php Reply with quote

Code:
<?php
$do = unlink("/home/user/public_html/file.html");
if($do=="1"){
    echo "The file was deleted successfully.";
} else { echo "There was an error trying to delete the file."; }
?> 


i searched the net and found the above code for deleting the file. I have only one problem i cant seem to solve

I want to delete all the files that are called auctionnotsold.php and auctionwon.php which i ccan work out how to do to delete just those two. But there are several versions of them
auctionnotsold.php
auctionnotsold.php.1
auctionnotsold.php.10
auctionnotsold.php.100
and it goes on. How would i modify the above code to delete all files that are called auctionnotsold.php and auctionwon.php no matter what the .number is after them?
_________________
Midnight Tempest - A Sailor Moon TCG
Balanced Force - A Star Wars TCG
Back to top
 
ClickFanatic
Est. 2005


Joined: 18 Jan 2005
Posts: 3857


PostPosted: Wed Oct 17, 2007 7:36 am    Post subject: Reply with quote

You can retrieve an array of filepaths matching a certain pattern using the glob() function.
Then, for each item in this array, you would call the unlink() function.
Like so:
Code:
<?php
// Note the use of * as a wildcard
$files = glob('/path/to/dir/auctionnotsold.php*');
foreach($files as $file)
{
   if(unlink($file))
      echo $file . ' has been deleted<br />';
   else
      echo 'Could not delete ' . $file . '<br />';
}
?>

_________________
Captain Jell-O Buster from the Future
[img]http://feeds.feedburner.com/sparepencil.1.gif[/img]
Back to top
 
Display posts from previous:   
Post new topic   Reply to topic    Lifelesspeople.com Forum Index -> Web Architects' Abode All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Home | Hosting | News | Forum | Links | System Status | About | Archive | Donate ]
Powered by phpBB © 2001, 2002 phpBB Group
All trademarks and copyrights on this page are owned by their respective owners. Posts and comments are owned by the poster. Everything else © 2001 - 2007 Lifelesspeople.com