当我在Plesk的预定任务中运行PHP脚本时,目录是不同的
我使用这个当我在Plesk的预定任务中运行PHP脚本时,目录是不同的,php,scheduled-tasks,plesk,Php,Scheduled Tasks,Plesk,我使用这个clear.php脚本删除正确clear目录中的所有文件和文件夹: <?php function deleteDir($dirPath) { if (! is_dir($dirPath)) { throw new InvalidArgumentException("$dirPath must be a directory"); } if (substr($dirPath, strlen($dirPath) - 1, 1) != '/')
clear.php
脚本删除正确clear
目录中的所有文件和文件夹:
<?php
function deleteDir($dirPath) {
if (! is_dir($dirPath)) {
throw new InvalidArgumentException("$dirPath must be a directory");
}
if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
$dirPath .= '/';
}
$files = glob($dirPath . '*', GLOB_MARK);
foreach ($files as $file) {
if (is_dir($file)) {
deleteDir($file);rmdir($file);
} else {
unlink($file);
}
}
}
deleteDir('clear');
?>
传递绝对目录或确保相对路径从
php cli
所在位置开始感谢您的工作。传递绝对目录或确保相对路径从php cli
所在位置开始感谢您的工作。
Task "httpdocs/clear.php" completed with error in 0 seconds, output:
PHP Fatal error: Uncaught InvalidArgumentException: clear must be a directory in /var/www/vhosts/domain_name.com/httpdocs/clear.php:4
Stack trace:
#0 /var/www/vhosts/domain_name.com/httpdocs/clear.php(19): deleteDir('clear')
#1 {main}
thrown in /var/www/vhosts/domain_name.com/httpdocs/clear.php on line 4