Example #1
0
 /**
  * Moves a file from oldpath to newpath<br/>
  * Required permissions:<br/>
  * <ul>
  * <li>IS_AUTH</li>
  * </ul>
  * @param string $oldPath The directory where the file currently resides, relative to the base folder specified in the config.ini
  * @param string $newPath The target directory, relative to the base folder specified in the config.ini
  * @param string $filename The file to move
  * @return array The contents of oldpath
  * @throws \Exception
  */
 public function moveFile($oldPath, $newPath, $filename)
 {
     if (!$this->IS_AUTH) {
         throw $this->throwException(AuthenticationException::NO_USER_AUTH);
     }
     if (!is_dir(BASEPATH . UPLOADFOLDER . $oldPath)) {
         throw $this->throwException(FilesException::PARENT_NOT_FOUND);
     }
     if (!file_exists(BASEPATH . UPLOADFOLDER . $oldPath . $filename)) {
         throw $this->throwException(FilesException::FILE_NOT_FOUND);
     }
     if (file_exists(BASEPATH . UPLOADFOLDER . $newPath . $filename)) {
         throw $this->throwException(FilesException::DUPLICATE_FILENAME);
     }
     $thumbParts = explode('.', $filename);
     $thumbParts[count($thumbParts) - 2] .= '__thumb__';
     $thumb = join('.', $thumbParts);
     $ext = $thumbParts[count($thumbParts) - 1];
     if (file_exists(BASEPATH . UPLOADFOLDER . $oldPath . $thumb)) {
         rename(BASEPATH . UPLOADFOLDER . $oldPath . $thumb, BASEPATH . UPLOADFOLDER . $newPath . $thumb);
     }
     if (strpos($filename, '__thumb__') !== false) {
         // Dragged file IS a thumb, move original too
         $thumbParts = explode('__thumb__', $filename);
         $thumb = join('', $thumbParts);
         if (file_exists(BASEPATH . UPLOADFOLDER . $oldPath . $thumb)) {
             rename(BASEPATH . UPLOADFOLDER . $oldPath . $thumb, BASEPATH . UPLOADFOLDER . $newPath . $thumb);
         }
     }
     if (strtolower($ext) === 'pdf') {
         // Update page
         $page = new Page();
         $p = $page->getPageByLabel(md5($oldPath . $filename));
         if ($p) {
             $p->label = md5($newPath . $filename);
             $p->content->path->all = $oldPath . $filename;
             $page->setPage($p);
         } else {
             // Re-index
         }
     }
     rename(BASEPATH . UPLOADFOLDER . $oldPath . $filename, BASEPATH . UPLOADFOLDER . $newPath . $filename);
     return $this->getFiles($oldPath);
 }