public function deleteFile($fileId) { $this->load->helper('file'); $fileDataObj = new Document_Model($fileId); $userPermObj = new User_Perms_Model($this->session->id); // all ok, proceed! if (!is_dir($this->config->item('archiveDir'))) { // Make sure directory is writeable if (!mkdir($this->config->item('archiveDir'), 0775)) { $error = array('status' => 'error', 'msg' => 'We could not create the Archive Directory'); return json_encode($error); exit; } } if ($userPermObj->canAdmin($fileId)) { $location = $fileDataObj->getLocation(); $baseName = $fileDataObj->getBaseName(); $ext = $fileDataObj->getExt(); $fileDataObj->temp_delete(); $fileContent = file_get_contents($this->config->item('dataDir') . $location); if (!write_file($this->config->item('archiveDir') . $location, $fileContent)) { $error = array('status' => 'error', 'msg' => 'Unable to create the archived file.'); return json_encode($error); exit; } else { unlink($this->config->item('dataDir') . $location); } } else { $error = array('status' => 'error', 'msg' => 'You do not have admin priviledges for this file.'); return json_encode($error); exit; } AccessLog_model::addLogEntry($fileId, 'X'); $msg = array('status' => 'success', 'msg' => 'File was successfully archived'); return json_encode($msg); }