sorry for my late answer. I got some errors with this code, but now it works for me. I have done some changes.
I made a admin_autodelete.php with this code:
- Code: Select all
<?php
require_once("./config.php");
//delete old files
echo " ******* DFH Autodelete ******* \r\n";
echo "\r\n__________\r\nDeleting old files...\r\n";
$deleteseconds = time() - ($deleteafter * 24 * 60 * 60);
$dirname = "./files";
$dh = opendir( $dirname ) or die("couldn't open directory");
while ( $file = readdir( $dh ) ) {
if ($file != '.' && $file != '..' && $file != ".htaccess") {
$fh=fopen("./files/" . $file ,r);
$filedata= explode('|', fgets($fh));
if ($filedata[4] < $deleteseconds) {
$deletedfiles="yes";
echo "Deleting - " . $filedata[1] . ":\r\n";
fclose($filedata);
unlink("./files/".$file);
echo "Deleted /files/" . $file . "\r\n";
unlink("./storage/".str_replace(".dfh","",$file));
echo "Deleted /storage/" . str_replace(".dfh","",$file) . "\r\n \r\n";
if ($filedata[10] <> "") {
unlink("./userfiles/files/" .$filedata[10] ."/" .$file);
echo "Deleted ./userfiles/files/" .$filedata[10] ."/" .$file;
}
}
fclose($fh);
}
}
closedir( $dh );
if (!$deletedfiles) echo "No old files to delete!\r\n \r\n";
//reset var deletedfiles
$deletedfiles="";
echo "\r\n__________\r\nDeleting old images...\r\n";
$deleteseconds = time() - ($deleteafter * 24 * 60 * 60);
$dirname = "./imgfiles";
$dh = opendir( $dirname ) or die("couldn't open directory");
while ( $file = readdir( $dh ) ) {
if ($file != '.' && $file != '..' && $file != ".htaccess") {
$fh=fopen("./imgfiles/" . $file ,r);
$filedata= explode('|', fgets($fh));
if ($filedata[6] <> "") {
unlink("./userfiles/images/" .$filedata[6] ."/" .$file);
}
if ($filedata[4] < $deleteseconds) {
$deletedfiles="yes";
echo "Deleting - " . $filedata[1] . ":\r\n";
fclose($filedata);
unlink("./imgfiles/".$file);
echo "Deleted /imgfiles/" . $file . "\r\n";
unlink("./images/".str_replace(".dfh","",$file));
echo "Deleted /images/" . str_replace(".dfh","",$file) . "\r\n \r\n";
unlink("./thumbs/".str_replace(".dfh","",$file));
echo "Deleted /thumbs/" . str_replace(".dfh","",$file) . "\r\n \r\n";
}
fclose($fh);
}
}
closedir( $dh );
if (!$deletedfiles) echo "No old images to delete!\r\n";
//done deleting old files
die();
?>
Run this code in dfh folder:
- Code: Select all
php admin_autodelete.php
Works fine for me!
Thx!!!
Best regards
Franky