Home  >  Q&A  >  body text

Cron execution for PHP - mkdir() fails but manual execution succeeds

I need to create a daily directory (/YYYYMMDD). I'm using mkdir() function. When I run it manually it works fine, but when it is executed by cron it fails to create the directory.

I thought the problem was with the permissions, but I even tried modifying the directory to 777 and it still didn't work.

This is how I use mkdir():

if (!file_exists($auxfile)) {
    if (!@mkdir($auxfile, 0777, true)) {
        $error = error_get_last();
        echo $error['message'];
    }
}

P粉904405941P粉904405941226 days ago469

reply all(1)I'll reply

  • P粉381463780

    P粉3814637802024-03-31 12:47:04

    If you are doing it old-style via the examples in DirectAdmin. You need to make sure you use the main path. For example. mkdir('/home/DOMAIN.COM/public_html/results/'.$auxfile);

    reply
    0
  • Cancelreply