Exemplo n.º 1
0
 /**
  * @return string|false
  */
 public function moveToUpload()
 {
     $filename = sha1(microtime());
     $ext = pathinfo($this->getName(), PATHINFO_EXTENSION);
     $upload_path = File\Module::module()->upload_path;
     $p1 = StringHelper::byteSubstr($filename, 0, 2);
     $p2 = StringHelper::byteSubstr($filename, 2, 2);
     $path = $upload_path . DIRECTORY_SEPARATOR . $p1 . DIRECTORY_SEPARATOR . $p2;
     if (!file_exists($path)) {
         FileHelper::createDirectory($path);
     }
     $file_path = $path . DIRECTORY_SEPARATOR . $filename . '.' . $ext;
     $result = copy($this->getTemp(), $file_path);
     $this->clear();
     chmod($file_path, 0664);
     return $result === true ? $file_path : false;
 }
Exemplo n.º 2
0
 /**
  * @return static
  */
 public static function getNoImage()
 {
     $image = \Yii::getAlias(\rmrevin\yii\module\File\Module::module()->no_image_alias);
     $Resource = new \rmrevin\yii\module\File\resources\InternalResource($image);
     return static::push($Resource);
 }
Exemplo n.º 3
0
 /**
  * @expectedException \RuntimeException
  */
 public function testNotWritableStoragePath()
 {
     $Module = clone File\Module::module();
     $Module->storage_alias = '/usr';
     $Module->storage_path = '/usr';
     $Module->init();
 }
Exemplo n.º 4
0
 /**
  * @return string[]
  */
 private function getPath()
 {
     $filename = basename($this->File->name);
     $p1 = StringHelper::byteSubstr($filename, 0, 2);
     $p2 = StringHelper::byteSubstr($filename, 2, 2);
     $p = DIRECTORY_SEPARATOR . $p1 . DIRECTORY_SEPARATOR . $p2;
     return [Module::module()->storage_path . $p, Module::module()->storage_web_path . $p];
 }