/** * This function deletes a file or an array of files from the * target directory. * * @param $files The file name or an array of filenames * relative to the target directory. * * @returns An array with the results. */ function deleteFile($files) { if (!is_array($files)) { $files = array($files); } $res = array(); foreach ($files as $file) { // The file path $file = YDPath::join($this->_target_dir, $file); if (!is_file($file)) { $res[] = array('success' => false, 'action' => 'delete', 'type' => 'file', 'item' => $file, 'reason' => 'exist'); if ($this->_log) { YDLog::warning('Deleting file: ' . $file . ' - already exist'); } continue; } // Target directory path $dir = YDPath::getDirectoryName($file); // The directory $d = new YDFSDirectory($dir); // Delete the file if (!($success = $d->deleteFile($file))) { if ($this->_log) { YDLog::error('Deleting file: ' . $file); } } else { if ($this->_log) { YDLog::info('Deleting file: ' . $file); } } $res[] = array('success' => $success, 'action' => 'delete', 'type' => 'file', 'item' => $file, 'reason' => 'failure'); } return $res; }