generateRandomPath() public method

Generates a $n level folder tree with random integer by exploding the filename
public generateRandomPath ( boolean $createDir = false, string $uploadRootPath = './', integer $level = 3 ) : string
$createDir boolean
$uploadRootPath string upload root path
$level integer
return string
Ejemplo n.º 1
0
 /**
  * @param $file
  * @param bool $isImage
  * @return string
  */
 private function storeFile($file, $isImage = false)
 {
     $fs = new Filesystem();
     $rootDir = $this->kernel->getRootDir();
     $issueFileDir = $rootDir . '/../web/uploads/issuefiles/';
     $journalUploadDir = $rootDir . '/../web/uploads/journal/';
     $fileHelper = new FileHelper();
     $randomPath = $fileHelper->generateRandomPath();
     $generateRandomPath = $randomPath . $file['filename'];
     if ($isImage) {
         $fs->dumpFile($journalUploadDir . $generateRandomPath, base64_decode($file['encoded_content']));
         $fs->dumpFile($journalUploadDir . 'croped/' . $generateRandomPath, base64_decode($file['encoded_content']));
         $this->apiHelper->createFileHistory($generateRandomPath, $generateRandomPath, 'journal', $this->om, true);
         return $generateRandomPath;
     } else {
         $fs->dumpFile($issueFileDir . $generateRandomPath, base64_decode($file['encoded_content']));
         $this->apiHelper->createFileHistory($generateRandomPath, $generateRandomPath, 'issuefiles', $this->om, true);
         return $generateRandomPath;
     }
 }
Ejemplo n.º 2
0
 private function storeFile($file, $isImage = false)
 {
     $rootDir = $this->kernel->getRootDir();
     $journalUploadDir = $rootDir . '/../web/uploads/journal/';
     if ($isImage) {
         $fileHelper = new FileHelper();
         $generatePath = $fileHelper->generateRandomPath();
         if (!is_dir($journalUploadDir . $generatePath) || !is_dir($journalUploadDir . 'croped/' . $generatePath)) {
             mkdir($journalUploadDir . $generatePath, 0775, true);
             mkdir($journalUploadDir . 'croped/' . $generatePath, 0775, true);
         }
         $filePath = $generatePath . $file['filename'];
         file_put_contents($journalUploadDir . $filePath, base64_decode($file['encoded_content']));
         file_put_contents($journalUploadDir . 'croped/' . $filePath, base64_decode($file['encoded_content']));
         $this->apiHelper->createFileHistory($filePath, $filePath, 'journal', $this->om, true);
         return $filePath;
     }
 }
Ejemplo n.º 3
0
 private function storeFile($file)
 {
     if (!is_array($file)) {
         return $file;
     }
     $fileHelper = new FileHelper();
     $rootDir = $this->kernel->getRootDir();
     $issueFileDir = $rootDir . '/../web/uploads/issuefiles/';
     $generateUniqueFilePath = $fileHelper->generateRandomPath() . $file['filename'];
     $fs = new Filesystem();
     $fs->mkdir($issueFileDir);
     $fs->dumpFile($issueFileDir . $generateUniqueFilePath, base64_decode($file['encoded_content']));
     $this->apiHelper->createFileHistory($generateUniqueFilePath, $generateUniqueFilePath, 'issuefiles', $this->om, true);
     return $generateUniqueFilePath;
 }