Ejemplo n.º 1
0
 protected function prepareDirs()
 {
     if (!is_dir($this->path)) {
         FPM::mkdir($this->path, 0777);
     } else {
         if (!is_writable($this->path)) {
             chmod($this->path, 0777);
         }
     }
     if (!is_dir($this->pathTmp)) {
         FPM::mkdir($this->pathTmp, 0777);
     } else {
         if (!is_writable($this->pathTmp)) {
             chmod($this->pathiTmp, 0777);
         }
     }
 }
 /**
  * @param string $file path to the file
  *
  * @throws \Exception
  * @return mixed
  */
 public function saveFileByCopy($file)
 {
     $id = $this->saveMetaDataForFile($file);
     $realName = pathinfo($file, PATHINFO_FILENAME);
     $ext = \mb_strtolower(pathinfo($file, PATHINFO_EXTENSION), 'UTF-8');
     $dirName = $this->getBaseDestinationDir() . DIRECTORY_SEPARATOR . floor($id / $this->getMaxFilesPerDir());
     if (!is_dir($dirName)) {
         FPM::mkdir($dirName, 0777, true);
     }
     $fileName = $dirName . DIRECTORY_SEPARATOR . $id . '-' . $realName . ($ext ? '.' . $ext : null);
     if (!copy($file, $fileName)) {
         throw new \Exception('Can not copy file from ' . $file . ' to ' . $fileName);
     }
     return $id;
 }
Ejemplo n.º 3
0
 protected function getPath2Dir($id)
 {
     if ($id > 0) {
         $dirName = floor($id / FPM::m()->filesPerDir);
         $path2Dir = FPM::m()->baseDir . FPM::m()->originalBaseDir . DIRECTORY_SEPARATOR . $dirName;
         if (!is_dir($path2Dir)) {
             FPM::mkdir($path2Dir, 0777, true);
         }
         return $path2Dir;
     }
     return null;
 }
Ejemplo n.º 4
0
 /**
  * @param $id
  * @param $model
  * @param $type
  *
  * @throws CException
  */
 public static function createCacheDir($id, $model, $type)
 {
     $dirName = FPM::getBasePath() . FPM::m()->cachedImagesBaseDir . DIRECTORY_SEPARATOR . floor($id / FPM::m()->filesPerDir) . DIRECTORY_SEPARATOR . $model . '_' . $type;
     if (!is_dir($dirName)) {
         FPM::mkdir($dirName, 0777, true);
     }
 }