123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- namespace cmf\lib\storage;
- class Local
- {
- private $config;
-
- public function __construct($config)
- {
- $this->config = $config;
- }
-
- public function upload($file, $filePath = '', $fileType = 'image', $param = null)
- {
- return [
- 'preview_url' => $this->getPreviewUrl($file),
- 'url' => $this->getUrl($file),
- ];
- }
-
- public function getImageUrl($file, $style = '')
- {
- return $this->_getWebRoot() . '/upload/' . $file;
- }
-
- public function getPreviewUrl($file, $style = '')
- {
- return $this->_getWebRoot() . '/upload/' . $file;
- }
-
- public function getUrl($file, $style = '')
- {
- return $this->_getWebRoot() . '/upload/' . $file;
- }
-
- public function getFileDownloadUrl($file, $expires = 3600)
- {
- $url = $this->getUrl($file);
- return $url;
- }
-
- public function getDomain()
- {
- return request()->host();
- }
-
- public function getFilePath($url)
- {
- $storageDomain = $this->getDomain();
- $url = preg_replace("/^http(s)?:\/\/$storageDomain/", '', $url);
- $url = preg_replace("/^\/upload\//", '', $url);
- return $url;
- }
- private function _getWebRoot()
- {
- return STATICSITE;
- }
- }
|