delete file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

delete file

Post by irealms »

i want a user to be able to press a link that deletes a record from a database and a file at the same time. I know how to delete from a database but how do i delete a file from the directory?
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

I could give you an easy example but it'll be better for you if you do it yourself :wink: . Check out: http://us2.php.net/unlink. If you need it, $_SERVER['DOCUMENT_ROOT'] will start the path to the file at the root directory.
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

Post by irealms »

ok thanks , so something like :

int unlink ('uploads/'.$_GET[remove].'');

where the $_GET is the filename i want to delete
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

Yeah that should work. Though I'm not sure why you have "int" at the beggining of the line.
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

Post by irealms »

works great thanks :)
Post Reply