/** * Constructor. Parameters are filebase-"root"-directory and cache-dir for * e.g. temp-files and thumbnails. * * You can specify $path_name and $cache_directory by yourself, but you don't * have to. In symfony context, the $path_name is * app.yml: * sf_filebase_plugin: * path_name: /your/path/to/filebase * cache_directory: /your/path/to/.cache * * or, if not defined, calculated from the predefined sfConfig-variables: * $path_name = sfConfig::get('sf_upload_dir') => web/uploads * $cache_directory = sfConfig::get('sf_upload_dir') . '/.hash_from_clasname' * * @param string $cache_directory: Cache directory may explicitely be * specified. Consider that the default * directory is accessible via browser. * Default is a subdirectory of * sfConfig::get('sf_upload_dir') * @param string $filebaseDirectory: Filebase directory may explicetly be * specified. Consider that the default * directory is accessible via browser. * Default is sfConfig::get('sf_upload_dir') * @param boolean $create True if the filebase should try to * create its base directory if it does * not exist. * @throws sfFilebasePluginException * @param string $mode */ public function __construct($id, $path_name, $cache_directory = null) { parent::__construct($path_name, $this); if (!$this->fileExists()) { // Should filebase dir be created by default? $p = $this->getFilebaseFile($this->getPath()); if ($p->isWritable()) { if (!@mkdir($this->getPathname())) { throw new sfFilebasePluginException(sprintf('Error creating filebase base directory %s: %', $this->getPathname(), implode("\n", error_get_last()))); } } else { throw new sfFilebasePluginException(sprintf('Filebase base directory %s cannot be created due to write protection of its parent directory.', $this->getPathname())); } } if (!$this->isDir()) { throw new sfFilebasePluginException(sprintf('Filebase base directory %s is not a directory', $this->getPathname())); } if (!$this->isReadable()) { throw new sfFilebasePluginException(sprintf('Filebase base directory %s is not readable', $this->getPathname())); } // Filebase root must have read/write-access. if (!$this->isWritable()) { throw new sfFilebasePluginException(sprintf('Filebase base directory %s is read or write protected', $this->getPathname())); } // Initialize cache. $this->cache = new sfFilebasePluginCache($this); $this->uploadedFilesManager = new sfFilebasePluginUploadedFilesManager($this); }
/** * Constructor. Parameters are filebase-"root"-directory and cache-dir for * e.g. temp-files and thumbnails. * * You can specify $path_name and $cache_directory by yourself, but you don't * have to. In symfony context, the $path_name is * app.yml: * sf_filebase_plugin: * path_name: /your/path/to/filebase * cache_directory: /your/path/to/.cache * * or, if not defined, calculated from the predefined sfConfig-variables: * $path_name = sfConfig::get('sf_upload_dir') => web/uploads * $cache_directory = sfConfig::get('sf_upload_dir') . '/.hash_from_clasname' * * @param string $cache_directory: Cache directory may explicitely be * specified. Consider that the default * directory is accessible via browser. * Default is a subdirectory of * sfConfig::get('sf_upload_dir') * @param string $filebaseDirectory: Filebase directory may explicetly be * specified. Consider that the default * directory is accessible via browser. * Default is sfConfig::get('sf_upload_dir') * @param boolean $create True if the filebase should try to * create its base directory if it does * not exist. * @throws sfFilebasePluginException * @param string $mode */ function __construct($path_name = null, $cache_directory = null, $create = true, $dir_chmod = 0777) { if ($path_name === null) { $path_name = sfConfig::get('app_sf_filebase_plugin_path_name', sfConfig::get('sf_upload_dir')); } if ($cache_directory === null) { $cache_directory = sfConfig::get('app_sf_filebase_plugin_cache_directory', $path_name . '/.' . md5(get_class())); } $path_name === null && ($path_name = sfConfig::get('sf_upload_dir', null)); parent::__construct($path_name, $this); if (!$this->fileExists()) { // Should filebase dir be created by default? if ($create) { $p = $this->getFilebaseFile($this->getPath()); if ($p->isWritable()) { if (!@mkdir($this->getPathname())) { throw new sfFilebasePluginException(sprintf('Error creating filebase base directory %s: %', $this->getPathname(), implode("\n", error_get_last()))); } if (!@chmod($this->getPathname(), $dir_chmod)) { throw new sfFilebasePluginException(sprintf('Error changing directory permissions for filebase base directory %s: %', $this->getPathname(), implode("\n", error_get_last()))); } } else { throw new sfFilebasePluginException(sprintf('Filebase base directory % cannot be created due to write protection of its parent directory.', $this->getPathname())); } } else { throw new sfFilebasePluginException(sprintf('Filebase base directory %s does not exist.', $this->getPathname())); } } if (!$this->isDir()) { throw new sfFilebasePluginException(sprintf('Filebase base directory %s is not a directory', $this->getPathname())); } if (!$this->isReadable()) { throw new sfFilebasePluginException(sprintf('Filebase base directory %s is not readable', $this->getPathname())); } // Filebase root must have read/write-access. if (!$this->isWritable()) { throw new sfFilebasePluginException(sprintf('Filebase base directory %s is read or write protected', $this->getPathname())); } // Initialize cache. $this->initCache($cache_directory); $this->uploadedFilesManager = new sfFilebasePluginUploadedFilesManager($this); $this->gfxEditor = new sfFilebasePluginGfxEditor($this); }