CRONTAB Permission Denied Deleting Files

dotcomtim

Member
Jan 20, 2010
11
0
51
I am using crontab to execute a PHP script to delete files and the directory after the files have been deleted. I keep getting permission denied when using the unlink command on the files.

Here is the PHP Script I am running.
Code:
function RemoveDirectory($dirname) {
    if (!file_exists($dirname)) {
        return false;
    }
    if (is_file($dirname) || is_link($dirname)) {
        return unlink($dirname);
    }
    $dir = dir($dirname);
    while (false !== $entry = $dir->read()) {
        if ($entry == '.' || $entry == '..') {
            continue;
        }
        RemoveDirectory($dirname . DIRECTORY_SEPARATOR . $entry);
    }
    $dir->close();
    return rmdir($dirname);
}

$dirName = 123;
if (is_dir('/home/xxx/public_html/library/'.$dirName)) {
	RemoveDirectory('/home/xxx/public_html/library/'.$dirName);
}
The files are JPG images upload using PHP. The file permissions are 0644 user and group are 99. The directory itself is 777 user and group is 99 as well.

How do I give access to crontab to run this script and delete the files and directory?

If I run the script myself directly with the CMS I am using - no problems. Which means there is a permissions issue somewhere that needs to be fixed.

Any help appreciated. Thanks.
 

dotcomtim

Member
Jan 20, 2010
11
0
51
Tried that as well. The server is setup as DSO and I am wondering if this has something to do with it.
 

quietFinn

Well-Known Member
Feb 4, 2006
1,386
174
193
Finland
cPanel Access Level
Root Administrator
What is the command line you use to start the script in crontab?