Example #1
0
 /**
  * Возвращает html тег изображения. Производит ресайз
  * @param string $path путь к файлу
  * @param int $width ширина изображения
  * @param int $height высота изображения
  * @return string
  */
 protected function renderImageTag($path, $width, $height)
 {
     if (!is_file($path) or !FileHelper::isImage($path)) {
         return "";
     }
     $options = array_merge(["src" => Yii::$app->resizer->resize($path, $width, $height), "class" => "img-thumbnail detail-img"], $this->imageOptions);
     return Html::tag('img', '', $options);
 }
Example #2
0
 /**
  * Разрешен ли файл к загрузке
  * @param $file UploadedFile
  * @return bool
  */
 protected function isAllowedToUpload($file)
 {
     $ext = FileHelper::getExtension($file->name);
     return in_array($ext, $this->allowed);
 }
Example #3
0
 /**
  * Возвращает имя изображени для охранения
  * @param string $path путь к изображению
  * @param int $width ширина
  * @param int $height высота
  * @return string
  */
 public function getThumbName($path, $width, $height)
 {
     $md5 = md5($path . filectime($path) . $width . $height);
     $ext = FileHelper::getExtension($path);
     return $md5 . "." . $ext;
 }
Example #4
0
 public function getSaveRelativePath()
 {
     if (!$this->_saveRelativePath) {
         $subDir = date('Ym/');
         if (!file_exists(Yii::getAlias($this->savePath . $subDir))) {
             FileHelper::createDirectory(Yii::getAlias($this->savePath . $subDir));
         }
         $this->_saveRelativePath = $subDir . $this->newFileName;
     }
     return $this->_saveRelativePath;
 }
Example #5
0
        <?php 
if (is_array($files)) {
    $i = 0;
    foreach ($files as $file) {
        ?>

                <li>
                    <div class="uploader-widget-name"><?php 
        echo basename($file["file"]);
        ?>
</div>
                    <div class="uploader-widget-preview">

                        <?php 
        if (is_file(Yii::getAlias($webroot . $file["file"])) and FileHelper::isImage(Yii::getAlias($webroot . $file["file"]))) {
            ?>

                            <img src="<?php 
            echo $file["file"];
            ?>
" width="150" alt=""/>

                        <?php 
        }
        ?>

                    </div>
                    <div class="uploader-widget-progress progress-bar"></div>

                    <input type="hidden" name="<?php 
Example #6
0
 /**
  * Является ли файл изображением
  * @return bool
  */
 public function isImage()
 {
     return FileHelper::isImage($this->path);
 }