Exemple #1
0
 public static function GenerateFilename($id, $original, $allowed_extensions = null)
 {
     $extension = strtolower(pathinfo($original, PATHINFO_EXTENSION));
     $filename = preg_replace('~\\.$~', '', sha1($id) . '.' . $extension);
     $directory = UPLOADS_DIR . DIRECTORY_SEPARATOR . $filename[0] . DIRECTORY_SEPARATOR . $filename[1];
     $path = $directory . DIRECTORY_SEPARATOR . $filename;
     $uri = str_replace(Config::Get('document_root'), '', $path);
     // Check if the file extension is allowed
     if (!empty($allowed_extensions) && !in_array($extension, explode(',', strtolower($allowed_extensions)))) {
         throw new BaseException(_T('Validation:The file extension of the uploaded file is not allowed'));
     }
     // Create the directory if necessary
     if (!file_exists($directory)) {
         Dir::Create($directory);
     }
     return array('path' => $path, 'uri' => $uri, 'directory' => $directory, 'filename' => $filename);
 }
Exemple #2
0
 private function CreateFromExisting($directory)
 {
     $this->base_dir = $directory;
     $this->clips_dir = $directory . '/' . self::CLIPS;
     Dir::Create($this->clips_dir);
     $this->temp_dir = $directory . '/' . self::TEMP;
     Dir::Create($this->temp_dir);
     $this->processing_dir = $directory . '/' . self::PROCESSING;
     Dir::Create($this->processing_dir);
     $this->originals_dir = $directory . '/' . self::ORIGINALS;
     Dir::Create($this->originals_dir);
     $this->thumbs_dir = $directory . '/' . self::THUMBS;
     Dir::Create($this->thumbs_dir);
 }