Resizing batch of images with with yiic cronjob

50 views Asked by At

I have this problem, I want to execute a cronjob but when I run the cron manually for testing I get permission issues.

I am using the Yii framework and I call the cronjob using Yiic. I want to create a directory structure where every directory contains an image. So we get like this:

/dir/id/  
/dir/id/imgsize-1  
/dir/id/imgsize-2  
/dir/id/imgsize-3

It get's more complex because it could be that imgsize-3 exists while imgsize-1 doesn't. And it could be possible that /dir/id/ is not writeable (0755 perms) so I first need to check if the parent directory (/dir/id/) is writable. If so I should be able to use mkdir to create dir 'imgsize-1' or whatever is my thought so far.

But now the problem occurs that if I want to use chmod to make a the parentdirectory writable I get the error 'chmod: 'path/to/dir' operation not permitted' and after that ofcourse that mkdir results in 'Permission denied'.

How can I solve this. When I use ls -la on the specific directorie I want to make writable I get the following:

 4 drwxr-xr-x     9 nobody nobody

Is there someone who can help me with this?

b.t.w. I execute the CLI-commands in PHP with shell_exec.

Kind regards,

Pim

1

There are 1 answers

0
dtmiRRor On

in your command action you should have something like this:

$dir = '/your/path';
if (!is_dir($dir))
    mkdir($dir, 0777, true);

Then, running the cron (what's the user you're running the command with?) with the command php yiic yourCommand, the directory should be created in /your/path