d3yii2/d3files

View on GitHub
views/d3filedownload/file_download.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php
use yii\helpers\Html;
use yii\bootstrap\Modal;

$imageExtensions = Yii::$app->getModule('d3files')->imageExtensions;
$fileExtension   = pathinfo($fileName, PATHINFO_EXTENSION);

if (in_array($fileExtension, $imageExtensions)) {
    Modal::begin(['id' => 'modal-image', 'size' => 'modal-lg']);
    echo Html::img(
        [$downloadUrl, 'id' => $fileModelId],
        ['style' => 'max-width: 100%; max-height: 100%']
    );
    Modal::end();

    echo Html::a(
        Html::img(
            [$downloadUrl, 'id' => $fileModelId],
            ['style' => 'width: 100px;',]
        ),
        '#',
        ['data-toggle' => 'modal', 'data-target' => '#modal-image']
    );
} else {
    echo Html::a(
        Yii::t('d3files', 'Download') . ' ' . $fileName,
        [$downloadUrl, 'id' => $fileModelId],
        ['title' => Yii::t('d3files', 'Download')]
    );
}