Anil Kumar
Anil Kumar

Reputation: 711

yii2 image not loading in html img tag but showing in browser

I am using yii2 and storing the image in root folder images. I have pointed the new domain to image folder and its working fine also in browser images are getting upload also showing in a browser but when I am trying to use them in IMG tag than it is not showing.

for ref please check below url http://image.letspartii.com/advertisement/oJ9LFcAk2azVuGAHUrb8iyuuLqMJjUYa.png

Upvotes: 0

Views: 1554

Answers (1)

ThiagoYou
ThiagoYou

Reputation: 318

1 - All images you want to display must be stored inside the /web folder.

2 - Use the relative path to call the img (starting inside de /web).

3 - Make sure to have the correct permission to the img folder and the file inside /web (permission and web/apache group).

Use the Url::base() method to get relative path:

<img src="<?= yii\helpers\Url::base().'/img/'.$filename; ?>"/>

Upvotes: 1

Related Questions