Skip to content

Instantly share code, notes, and snippets.

@kane-thornwyrd
Created June 14, 2012 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kane-thornwyrd/2930977 to your computer and use it in GitHub Desktop.
Save kane-thornwyrd/2930977 to your computer and use it in GitHub Desktop.
suppression de fichier
<?php
$folder = file_directory_path() . '/' . $cache_folder . '/' . $resource_name;
$dh = @opendir($folder);
$folder .= '/';
$suppressed_file_nb = 0;
$files_suppressed_error_nb = 0;
$suppressed_file_errors = array();
if ($dh) {
while (($file = readdir($dh)) !== false) {
if (filetype($folder . $file) !== 'dir' && $file != '.' && $file != '..' && strlen(trim($file)) > 0) {
chmod($folder . $file, 0777);
$unlinking_passed = unlink($folder . $file);
if (!$unlinking_passed) {
$suppressed_file_errors[] = $folder . $file;
$files_suppressed_error_nb++;
}
else {
$suppressed_file_nb++;
}
}
}
closedir($dh);
$message = $caller . ' passed for !resource_name ! !nb Files suppressed with !error_nb errors !';
$message_args = array(
'!nb' => $suppressed_file_nb,
'!error_nb' => $files_suppressed_error_nb,
'!resource_name' => $resource_name,
);
watchdog('services_cache', $message, $message_args, WATCHDOG_INFO);
if ($files_suppressed_error_nb > 0) {
$error_message = 'Unable to suppress files : @files';
$error_message_args = array('@files' => print_r($folder . $file,TRUE));
$files = '<ul><li>' . implode('</li> <li>', $suppressed_file_errors) . '</li></ul>';
watchdog('services_cache', $error_message, $error_message_args,
WATCHDOG_EMERG);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment