Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Apr 2004
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    click a link to delete a file?

    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

  • #2
    Regular Coder
    Join Date
    Apr 2004
    Posts
    298
    Thanks
    0
    Thanked 23 Times in 23 Posts
    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

  • #3
    Regular Coder
    Join Date
    Mar 2004
    Posts
    232
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Example script:
    PHP Code:
    <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:
    PHP Code:
    if(isset($_POST['filed'])){
       
    unlink($_POST['file']);

    that's pretty easy...

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    PHP Code:
    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
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #5
    New Coder
    Join Date
    Apr 2004
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks guys.

    Actually I will probably make use of both your examples.

    Thanks Again.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •