Log in

View Full Version : Delete file that is currently running



Schmoopy
03-07-2009, 01:33 AM
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:



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?

magicyte
03-07-2009, 04:28 AM
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.

Twey
03-07-2009, 09:41 AM
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.

Schmoopy
03-07-2009, 11:20 AM
Yea I did think about that, right, well thanks for your replies :)