Esempio n. 1
0
 /**
  * Get and check the current file path
  *
  * @param FileManager $file_manager
  * @throws \Exception when the file name is empty while there is a target file or when the file is invalid
  * @return bool|string
  */
 public function getFilePath(FileManager $file_manager)
 {
     $current_file = $file_manager->getCurrentFile();
     $target_file = $file_manager->getTargetFile();
     if ($current_file->getFilename() == "" && !is_null($target_file->getFilename())) {
         throw new \Exception("Filename cannot be empty when there is a target file");
     }
     $root = $file_manager->getUploadPath();
     $dir_path = $file_manager->getDirPath();
     if (empty($dir_path)) {
         $dir = $root;
     } else {
         if (strcasecmp("../", $dir_path) >= 1) {
             throw new \Exception("Invalid filepath or filename");
         }
         $dir = $this->getFileManager()->DirTrim($root, $dir_path, true);
     }
     try {
         $file_manager->checkPath($dir);
         if (!is_null($target_file)) {
             $file_manager->checkPath($target_file->getFilepath(true));
         }
     } catch (\Exception $e) {
         throw new \Exception($e->getMessage(), $e->getCode());
     }
     return $dir;
 }
Esempio n. 2
0
 /**
  * Set the locations where the file is used in an array.
  *
  * This function requires a class that is set in the config with the function returnUsages.
  *
  * @param FileManager $file_manager
  */
 public function setUsages(FileManager $file_manager)
 {
     $usages = array();
     $usage_class = $file_manager->getUsagesClass();
     if ($usage_class != false) {
         /** @var mixed $usage_object */
         $usage_object = new $usage_class();
         $usages_result = $usage_object->returnUsages($this->getFilepath(true));
         if (!empty($usages_result)) {
             $usages = $usages_result;
         }
     }
     $this->usages = count($usages);
 }