Example #1
0
 public function unDeleteFile($fileId = null)
 {
     if (isset($fileId) && $fileId !== null) {
         $this->load->helper('file');
         $fileObj = new Document_Model($fileId);
         $fileObj->undelete();
         $location = $fileObj->getLocation();
         $fileContent = file_get_contents($this->config->item('archiveDir') . $location);
         if (!write_file($this->config->item('dataDir') . $location, $fileContent)) {
             $error = array('status' => 'error', 'msg' => 'There was a problem moving the file back to the main directory.');
             return json_encode($error);
         } else {
             unlink($this->config->item('archiveDir') . $location);
             $msg = array('status' => 'success', 'msg' => 'This file was successfully restored to the primary directory.');
             return json_encode($error);
         }
     } else {
         $error = array('status' => 'error', 'msg' => 'You must pass a valid file id number in order to un-delete it.');
         return json_encode($error);
     }
 }