...

View Full Version : click a link to delete a file?



neobolt
05-22-2004, 03:42 AM
I'm trying to create a link, so when the user clicks the link it will delete a file from a directory.

I've been messing around with the unload command with no success.

This is so a member can download a text database file. Then I need them to click the delete database link so that the database file gets deleted, so when new information is sent, a new database is created.

All I need to know is how to delete a file from my server by clicking a link.

Thanks

litebearer
05-22-2004, 03:45 AM
unlink is used to delete files - you could create a small script that deletes a file (unlinks) using a variable that is passed via the link.


ie link to deleteme.php --- pass variable/filename --- deletme.php takes the variable and deletes the file - then returns to the calling page

stophon4
05-22-2004, 10:24 PM
Example script:


<form action="delete.php" method="post">
<b>Name of file(on the server):</b><INPUT type='text' Name='file'><Br>
<INPUT type='Submit' Name='filed' Value='Delete File'>
</form>

Now the php:


if(isset($_POST['filed'])){
unlink($_POST['file']);
}

that's pretty easy...

raf
05-22-2004, 11:24 PM
easy ... but i think he asked for a delete-link. So then you just display the filename as a link with the name in the querystring. Like

<a href="removefile.php?file=test.php" title="Delete file 'test.php' from the server">test.php</a>

and then inside removefile.php, you'll have


if(isset($_GET['file'])){
unlink($_GET['file']);
}

but this is realy risky business because it would be very easy to manupulate the querystring to remove whatever files you want (like *.* or so), so you need to do some extra testing to see if the querystring isn't manipulated

neobolt
05-23-2004, 02:48 AM
Thanks guys.

Actually I will probably make use of both your examples.

Thanks Again.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum