/**
  * Publishes a file.
  * @param string $src the asset file to be published
  * @return array the path and the URL that the asset is published as.
  * @throws InvalidParamException if the asset to be published does not exist.
  */
 protected function publishFile($src)
 {
     \Yii::trace("src:{$src} ", __METHOD__);
     $dir = $this->hash($src);
     $fileName = basename($src);
     $dstDir = $this->basePath . DIRECTORY_SEPARATOR . $dir;
     $dstFile = $dstDir . DIRECTORY_SEPARATOR . $fileName;
     \Yii::trace("dstFile:{$dstFile} ", __METHOD__);
     if (!is_dir($dstDir)) {
         FileHelper::createDirectory($dstDir, $this->dirMode, true);
     }
     if ($this->linkAssets) {
         if (!is_file($dstFile)) {
             symlink($src, $dstFile);
         }
     } elseif (@filemtime($dstFile) < @filemtime($src)) {
         copy($src, $dstFile);
         if ($this->fileMode !== null) {
             @chmod($dstFile, $this->fileMode);
         }
     }
     $result = [$dstFile, $this->baseUrl . "/{$dir}/{$fileName}"];
     \Yii::trace("result:{$result} ", __METHOD__);
     return $result;
 }
Ejemplo n.º 2
0
 public static function getFile($fileName, $fileType = 'csv')
 {
     //make sure the file name is unqiue
     $fileName = Yii::$app->getRuntimePath() . '/temp/' . $fileName . '.' . strtolower($fileType);
     $filePath = dirname($fileName);
     if (!is_dir($filePath)) {
         FileHelper::createDirectory($filePath, 0777, true);
     }
     return $fileName;
 }
Ejemplo n.º 3
0
 /**
  * Generate the actual filesystem path for a filekey
  */
 protected function _getRealFilePath($filekey, $createDir = true)
 {
     $filekey = substr(sha1($filekey), 0, 32);
     $path = sprintf('%s/%s/', rtrim($this->_filepath, '/'), substr($filekey, 0, self::STUB_KEY_LENGTH));
     // ensure directory path exists
     if ($createDir && !is_dir($path)) {
         FileHelper::createDirectory($path);
     }
     return $path . $filekey;
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (!$this->uploadRootPath) {
         throw new InvalidConfigException('The "savePath" attribute must be set.');
     } else {
         $this->uploadRootPath = rtrim(Yii::getAlias($this->uploadRootPath), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
         if (!file_exists($this->uploadRootPath) && !FileHelper::createDirectory($this->uploadRootPath)) {
             throw new InvalidCallException('Directory specified in "savePath" attribute doesn\'t exist or cannot be created.');
         }
     }
 }
Ejemplo n.º 5
0
 /**
  *
  * @return \JamesMoss\Flywheel\Repository
  */
 private function getFlywheelRepo($module)
 {
     if (!isset($this->flywheel_config)) {
         $config_dir = \Yii::getAlias($module->flywheel_config);
         if (!file_exists($config_dir)) {
             FileHelper::createDirectory($config_dir);
         }
         $this->flywheel_config = new Config($config_dir);
     }
     if (!isset($this->flywheel_repo)) {
         $this->flywheel_repo = new Repository($module->flywheel_repo, $this->flywheel_config);
     }
     return $this->flywheel_repo;
 }
Ejemplo n.º 6
0
 /**
  * store cht log
  * @param null $filename filename
  * @return bool
  * @throws \pinst\exception\ExitException
  */
 public function store($filename = null)
 {
     if (empty($filename)) {
         $filename = \Pinst::$app->runtimePath . DIRECTORY_SEPARATOR . "msg";
         if (!is_dir($filename)) {
             FileHelper::createDirectory($filename);
         }
     }
     $filename .= DIRECTORY_SEPARATOR . $this->getProperty("client_id") . '_' . time();
     $fp = fopen($filename, "a+");
     if (!$fp) {
         return false;
     }
     foreach ($this->message as $msg) {
         fwrite($fp, '[' . date("Y/m/d H:i:s", $msg['time']) . ']' . $msg['content']);
     }
     fclose($fp);
 }