简体   繁体   English

PHP - mkdir() 手动工作,但在由 cron 执行时不工作

[英]PHP - mkdir() works manually but not when executed by cron

I need to create a daily directory (/YYYYMMDD).我需要创建一个每日目录 (/YYYYMMDD)。 I am using mkdir() function. It works fine when i run it manually, but when it is executed by cron, it is not able to create the directory.我正在使用 mkdir() function。当我手动运行它时它工作正常,但是当它由 cron 执行时,它无法创建目录。

I think the problem is about permissions, but I even tried modifying the directory to 777 and still not working.我认为问题出在权限上,但我什至尝试将目录修改为 777,但仍然无法正常工作。

Here is how I am using mkdir():这是我使用 mkdir() 的方式:

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

If you do it old-skool by example in DirectAdmin.如果您在 DirectAdmin 中以老式的方式进行操作。 You need to make sure to use the home path.您需要确保使用主路径。 Eg mkdir('/home/DOMAIN.COM/public_html/results/'.$auxfile);例如mkdir('/home/DOMAIN.COM/public_html/results/'.$auxfile);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM