public
Created

suppression de fichier

  • Download Gist
gistfile1.aw
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
<?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);
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.