Cleaning up files created by the web server

Many times when you are working with a web application on shared hosting, the server will create files. Depending on the server configuration, it is possible those files will be created by a user other than the account holder. If you are using shared hosting, and the server is running as 'nobody', 'apache' or 'www-root' you may not be able to delete the files.

This script determines the web server user with the whoami command, then finds and deletes any files it owns. Bear in mind it will delete them from the current directory down, so files higher up in the directory tree will not be removed.

PHP

<?php
$whoami = `whoami`;
echo $whoami;
$find 'find -delete -user '.$whoami;
`$find`;

Be careful with this script, it may delete files you wanted to keep.

A good practice is to use the whoami display to see which user the server is running as, then use find -user server to find the files that were created. Once you've checked it, you can allow the script to run. Remember to run the script through the browser or using wget.