Results 1 to 4 of 4

Thread: Delete file that is currently running

  1. #1
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default Delete file that is currently running

    Ok I know this sounds weird, but I want a file to delete itself, and then redirect somewhere - This obviously wouldn't work as the file would be deleted so wouldn't be able to read the next line of code.

    Basically I have an "install" file, which while there, redirects all other files to it for setup purposes and then once the user has configured it I want it to delete itself so other files don't redirect to it anymore.

    How could this be done?

    Please just ask if you want me to explain a bit more.

    I have actually made code that works below:

    PHP Code:
            if (mysql_query($query))
            {
                
    $link "index.php";
                
    redirect_to($link);
                
    unlink("install.php"); // install.php is the file being run
            

    Will this always work or is it bad practice?

  2. #2
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    You could make a file "delete.php" with the file name sent via the post method. Then it could unlink it... Also, the delete.php file could have a redirection link sent to it via php. Well? If you don't want that, I don't know if that code is bad practice or not.

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Er, well, creating a script that will delete an arbitrary file passed to it is an obvious security risk.

    Rather, try sending a GET variable along with the page to which you redirect that will instruct it to delete the install.php file if it exists.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Yea I did think about that, right, well thanks for your replies

Bookmarks

Posting Permissions

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