Cron作业 - 删除特定文件夹中的所有文件

use*_*092 4 php cron

我想用php删除名为"data"的文件夹中的所有文件,然后使用Cron Job

Cron Job设置为每小时运行一次脚本,但我失去了我应该写在空的内容

textfield以及如何删除php中特定文件夹内的所有文件?

请有人解释我并帮助我...

在此输入图像描述

固定它:

将delete.php放在空字段内

并在delete.php里面写下面的代码:

<?php


define('PATH', 'folder/');

function destroy($dir) {
    $mydir = opendir($dir);
    while(false !== ($file = readdir($mydir))) {
        if($file != "." && $file != "..") {
            chmod($dir.$file, 0777);
            if(is_dir($dir.$file)) {
                chdir('.');
                destroy($dir.$file.'/');
                rmdir($dir.$file) or DIE("couldn't delete $dir$file<br />");
            }
            else
                unlink($dir.$file) or DIE("couldn't delete $dir$file<br />");
        }
    }
    closedir($mydir);
}
destroy(PATH);
echo 'all done.';


?>
Run Code Online (Sandbox Code Playgroud)

Shu*_*man 6

如果要删除包含其内容的文件夹,请在cpanel中转到cron作业:

rm -rf /home/user/public_html/folder
Run Code Online (Sandbox Code Playgroud)

如果要删除此文件夹中的所有内容,请保留文件夹本身:

rm -f /home/user/public_html/folder/*
Run Code Online (Sandbox Code Playgroud)


NoL*_*ing 5

这是PHP中的一个函数,可以删除文件。

http://se2.php.net/unlink

还有,这里的例子;http://se2.php.net/manual/zh/function.unlink.php#108940

包含有关如何从目录中删除文件的信息(只需跳过底部的rmdir)

编辑:忘记了cron-thing。:)

如果您在/ home / a1206305 /中创建一个名为directory.php的文件,其内容如下:

<?php
    $path = "/home/a1206305/domain.com/data/";
    foreach(glob($path . "*") as $file)
    {
        if(is_file($path . $file))
            unlink($path . $file);
    }
?>
Run Code Online (Sandbox Code Playgroud)

然后在cron的第二个字段中,只需在directory.php中编写