View Single Post
Old 01-13-2025, 07:12 PM  
Pipecrew
Master of Gfy.com
 
Pipecrew's Avatar
 
Industry Role:
Join Date: Feb 2002
Posts: 14,885
Your missing commas in the directories array. Try this

<?php

$directories = [
'/path/to/directory1',
'/path/to/directory2',
'/path/to/directory3',
// Add more directories as needed
];

$threshold = 30 * 24 * 60 * 60; // 30 days in seconds

foreach ($directories as $directory) {
if (is_dir($directory)) {
$dir = opendir($directory);

if ($dir) {
while (($file = readdir($dir)) !== false) {
// Check if the file is a JPG
if (pathinfo($file, PATHINFO_EXTENSION) === 'jpg') {
$filePath = $directory . DIRECTORY_SEPARATOR . $file;

// Check if the file exists and is older than the threshold
if (file_exists($filePath) && time() - filemtime($filePath) > $threshold) {
if (unlink($filePath)) {
echo "Deleted: $filePath\n";
} else {
echo "Failed to delete: $filePath\n";
}
}
}
}

closedir($dir);
} else {
echo "Failed to open directory: $directory\n";
}
} else {
echo "Directory does not exist: $directory\n";
}
}

echo "Cleanup complete.\n";
?>
Pipecrew is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote