Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy. This forum is not for asking programming related questions.
My hosting control panel has a Cron job utility that lets me create them using a thing where I specify and time interval and a command line.
Problem is I'm not a Unix guy at all and I know squat about what the "command" should be, so...
There is a thing on my site where a temp file is created in a subdirectory, a special one created for that purpose. When the user exits he is supposed to do so by clicking on an "exit" button which deletes the temp file and redirects but, of course, many just use their browser "back" button. No way am I going to disable the "back" button, so that directory keeps getting cluttered up with temp files and I have to go in and delete them. So I'm thinking in terms of a cron job to delete than once a month or so. But I don't know what unix is for "delete all files." The effect is:
<?php
if ($dh = opendir('/your/directory/here'))
{
while (($file = readdir($dh)) !== false)
{
if ($file != '.' && $file != '..')
{
unlink($dir . $file);
//comment this out if you like
echo 'Deleted file: ' . $dir . $file . '<br />' . "\n";
}
}
}
closedir($dh);
For this to work, this directory must be writable. (chmod)
Then you would put this script's location into the cron command
Last edited by Benjamin on Sun Apr 18, 2010 2:24 pm, edited 2 times in total.
Reason:Please use [syntax=php]...[/syntax] tags. [code] tags have been depreciated.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
The OP isn't very familiar with unix commands.
I didn't feel advising rm -r or rmdir would be appropriate considering it could do lots of damage if not used correctly.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Those are really simple commands to understand. Using someone else's delete script is definitely not safer than understanding and applying simple shell commands. Use the right tool for the job, I would say
NOTE: The absolute path to rm is used because some servers are configured to ignore the -f argument and add the -i argument causing rm to prompt for every file. Using the full path bypasses this.
pytrin wrote:Why would you use a php script instead of a bash script or a simple command for this purpose?
Portability (run in safemode? Or different OS?), readability (Windows programmers have to work on the code base), etc.
Benjamin wrote:This is perfectly safe
Not if someone plays an evil trick on you with symlinks/hardlinks
On a side note, why not just store your temp file in the session. PHP already has a way to garbage collection session data. That's what that mechanism is for.