protected function getAllowedMimeTypes() { $filter = $this->options['filter']; if (!$filter) { return null; } if (!FileManagerUtility::endsWith($filter, '/')) { return array($filter); } static $mimes; if (!$mimes) { $mimes = parse_ini_file($this->options['mimeTypesPath']); } foreach ($mimes as $mime) { if (FileManagerUtility::startsWith($mime, $filter)) { $mimeTypes[] = strtolower($mime); } } return $mimeTypes; }
public static function getRealPath($path) { $path = str_replace('\\', '/', $path); $path = preg_replace('#/+#', '/', $path); $path = str_replace($_SERVER['DOCUMENT_ROOT'], '', $path); $path = FileManagerUtility::startsWith($path, '/') ? $_SERVER['DOCUMENT_ROOT'] . $path : $path; $path = FileManagerUtility::startsWith($path, '../') || !FileManagerUtility::startsWith($path, '/') ? realPath($path) : $path; $path = str_replace('\\', '/', $path); $path = str_replace($_SERVER['DOCUMENT_ROOT'], '', $path); $path = FileManagerUtility::endsWith($path, '/') ? $path : $path . '/'; return $path; }
public function __construct($options) { $this->options = array_merge(array('directory' => null, 'assetBasePath' => null, 'thumbnailPath' => null, 'mimeTypesPath' => strtr(dirname(__FILE__), '\\', '/') . '/MimeTypes.ini', 'documentRootPath' => null, 'dateFormat' => 'j M Y - H:i', 'maxUploadSize' => 2600 * 2600 * 3, 'maxImageDimension' => array('width' => 1024, 'height' => 768), 'upload' => false, 'destroy' => false, 'create' => false, 'move' => false, 'download' => false, 'allowExtChange' => false, 'safe' => true, 'filter' => null, 'chmod' => 0777, 'ViewIsAuthorized_cb' => null, 'DetailIsAuthorized_cb' => null, 'UploadIsAuthorized_cb' => null, 'DownloadIsAuthorized_cb' => null, 'CreateIsAuthorized_cb' => null, 'DestroyIsAuthorized_cb' => null, 'MoveIsAuthorized_cb' => null, 'showHiddenFoldersAndFiles' => false, 'UsageMode' => MTFM_USAGE_BASIC), is_array($options) ? $options : array()); // transform the obsoleted/deprecated options: if (!empty($this->options['maxImageSize']) && $this->options['maxImageSize'] != 1024 && $this->options['maxImageDimension']['width'] == 1024 && $this->options['maxImageDimension']['height'] == 768) { $this->options['maxImageDimension'] = array('width' => $this->options['maxImageSize'], 'height' => $this->options['maxImageSize']); } $assumed_root = null; if (!empty($this->options['documentRootPath'])) { $assumed_root = realpath($this->options['documentRootPath']); } if (empty($assumed_root)) { $assumed_root = realpath($_SERVER['DOCUMENT_ROOT']); } $assumed_root = strtr($assumed_root, '\\', '/'); $assumed_root = rtrim($assumed_root, '/'); $this->options['documentRootPath'] = $assumed_root; // only calculate the guestimated defaults when they are indeed required: if ($this->options['directory'] == null || $this->options['assetBasePath'] == null || $this->options['thumbnailPath'] == null) { $my_path = @realpath(dirname(__FILE__)); $my_path = strtr($my_path, '\\', '/'); if (!FileManagerUtility::endsWith($my_path, '/')) { $my_path .= '/'; } $my_assumed_url_path = str_replace($assumed_root, '', $my_path); // we throw an Exception here because when these do not apply, the user should have specified all three these entries! if (empty($assumed_root) || empty($my_path) || !FileManagerUtility::startsWith($my_path, $assumed_root)) { throw new FileManagerException('nofile'); } if ($this->options['directory'] == null) { $this->options['directory'] = $my_assumed_url_path . '../../Demos/Files/'; } if ($this->options['assetBasePath'] == null) { $this->options['assetBasePath'] = $my_assumed_url_path . '../../Demos/Files/../../Assets/'; } if ($this->options['thumbnailPath'] == null) { $this->options['thumbnailPath'] = $my_assumed_url_path . '../../Demos/Files/../../Assets/Thumbs/'; } } /* * make sure we start with a very predictable and LEGAL options['directory'] setting, so that the checks applied to the * (possibly) user specified value for this bugger acvtually can check out okay AS LONG AS IT'S INSIDE the DocumentRoot-based * directory tree: */ $new_root = $this->options['directory']; $this->options['directory'] = '/'; // use DocumentRoot temporarily as THE root for this optional transform $this->options['directory'] = $this->rel2abs_url_path($new_root . '/'); $this->managedBaseDir = $this->url_path2file_path($this->options['directory']); // now that the correct options['directory'] has been set up, go and check/clean the other paths in the options[]: $this->options['thumbnailPath'] = $this->rel2abs_url_path($this->options['thumbnailPath'] . '/'); $this->thumbnailCacheDir = $this->url_path2file_path($this->options['thumbnailPath']); // precalculate this value; safe as we can assume the entire cache dirtree maps 1:1 to filesystem. $this->thumbnailCacheParentDir = $this->url_path2file_path(self::getParentDir($this->options['thumbnailPath'])); // precalculate this value as well; used by scandir/view $this->options['assetBasePath'] = $this->rel2abs_url_path($this->options['assetBasePath'] . '/'); $this->options['mimeTypesPath'] = @realpath($this->options['mimeTypesPath']); if (empty($this->options['mimeTypesPath'])) { throw new FileManagerException('nofile'); } $this->options['mimeTypesPath'] = strtr($this->options['mimeTypesPath'], '\\', '/'); // getID3 is slower as it *copies* the image to the temp dir before processing: see GetDataImageSize(). // This is done as getID3 can also analyze *embedded* images, for which this approach is required. $this->getid3 = new getID3(); $this->getid3->setOption(array('encoding' => 'UTF-8')); //$this->getid3->encoding = 'UTF-8'; $this->getid3_cache = new MTFMCache(MTFM_MIN_GETID3_CACHESIZE); $this->icon_cache = array(array(), array()); }
/** * Return the filesystem absolute path for the relative or absolute URI path. * * Note: as it uses normalize(), any illegal path will throw an FileManagerException * * Returns a fully normalized filesystem absolute path. */ public function url_path2file_path($url_path) { $url_path = $this->rel2abs_url_path($url_path); $root = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']); if (FileManagerUtility::endsWith($root, '/')) { $root = substr($root, 0, -1); } $path = $root . $url_path; //$path = $this->normalize($path); -- taken care of by rel2abs_url_path already return $path; }