I have images saved in /web/uploads/PROJECT in Yii2. How do i display them on page? below is my codes but its broken link image.
Controller:
$img = Yii::$app->request->baseUrl.'/web/uploads/PROJECT/';
$image = Html::img($img.$img_obj['AVATAR'],["width"=>"600px"]);
View:
echo $data;
Do i have to set any rights to display it? Right-clicking and opening image in new tab shows the url "/web/uploads/PROJECT/3fioobapJ5vRk_wdCEzDJbQWyO66inWO.jpg" which seems to be correct but page displays "Not Found (#404)"
Can anyone kindly advise? Thanks!
You can change width as needed. //'yourimage', <--Replace this line with array as below ['label' => 'Your Image', 'format' => ['image',['width'=>'50']], 'value'=>function($model){ return('@web/images/'. $model->yourimage); }, ], You can change width as needed.
Strangely, using the below codes displays the images correctly.
$img = Url::to('@web/uploads/PROJECT/').$img_obj['AVATAR'];
$image = '<img src="'.$img.'" width="600" />';
<img src="<?= Yii::$app->request->baseUrl . '/backend/web/uploads/' . $model->profile_photo ?>" class=" img-responsive" >
<?php echo Html::img('@web/img/icon.png', ['class' => 'pull-left img-responsive']); ?>
The static images should be placed inside web/any_folder_name
to access in YII 2:
<?= Html::img('@web/any_folder_name/bg1.jpg', ['alt'=>'some', 'class'=>'thing']);?>
Add this code in your Grid View:
[
'attribute'=>'photo',
'value' => Html::a(Html::img(Yii::getAlias('@web').'/image/'.$st_data->photo, ['alt'=>'some', 'class'=>'thing', 'height'=>'100px', 'width'=>'100px']), ['site/zoom']),
'format' => ['raw'],
],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With