首页 文章

rename()无法在cron作业中工作

提问于
浏览
2

rename()从命令行运行正常,但是当从cron作业运行时,rename()不会 . 由于connect.php文件有效,我假设cron作业位于正确的目录中,但无法弄清楚为什么rename()不起作用 . 我尝试了绝对路径并且它们不起作用:

<?php 
include 'connect.php';

$oldlocation='xxx/xxx/'.$oldfilename;
$newlocation='yyyy/xxx/'.$newfilename;
$move=rename("$oldlocation","$newlocation");

cron作业:* * * * * / usr / bin / php /usr/xxx/xxx/xxx/xxx.php -q -f

我没有对服务器的root访问权限 . 这应该通过SHELL脚本运行吗?

2 回答

  • 2

    cron 执行时的当前路径是运行 cron 进程的用户的 home 目录 . 另见post .

    只需将相对路径更改为绝对路径即可解决问题 .

  • 0

    解决方案,而不是直接的目录问题(好吧):$ oldlocation ='xxx / xxx /'.$ oldfilename;必须更改为:$ oldlocation ='/ xxx / xxx /'.$ oldfilename;我想我错过了第一个/

相关问题