Trying to delete a directory using PHP after set amount of time via Cron job

Status
Not open for further replies.

gmtrashx

New Member
Messages
2
Reaction score
0
Points
1
Hello. I'm trying to delete a directory that temporarily holds files for about 24 hours.

I setup a cron job with this command
/usr/local/bin/php/home/gmtrashx/public_html/purge.php 2>&1 >> /home/gmtrashx/public_html/cron_output.log

The file paths for the cron job should be correct. I'm new to php and such so that might be my issue

<?php

$files = glob('./usrupload/server/php/*');
foreach($files as $file){
if(is_file($file))
unlink($file);
}
?>
That's ^ my php for deleting files in the temporary directory.
The cron_job.log seems to be empty aswell.
 

lylex10h

Active Member
Messages
982
Reaction score
71
Points
28
Why don't you just the following command:
rm -f /home/gmtrashx/public_html/directory_to_delete
 

gmtrashx

New Member
Messages
2
Reaction score
0
Points
1
Thank you for this. I didn't realize you could delete a directory or files within one through just cron. for anyone else needing the command this is what i used rm -f /home/<user>/public_html/<deletefilesfromthisdir>/*
 
Status
Not open for further replies.
Top