Reputation: 717
I use Yii2
and Windows 10 OS
. My images are stored in @root/uploads
folder.
I am able to upload them via alias
like this:
in config\bootstrap.php
:
Yii::setAlias('@root', realpath(dirname(__FILE__).'/../../'));
in upload method
:
$this->imageFile->saveAs(Yii::getAlias('@root') .'/uploads/' . $this->imageFile->baseName . '.' . $this->imageFile->extension);
Then I try to see an image in view
:
<?php echo Html::img('../../uploads/ring.jpg',['class' => 'img-center', 'width'=>150, 'heigth'=>150, 'alt'=>'no image']) ?>
But it is not there... What I missed? Is there some restrictions for the folder?
Upvotes: 0
Views: 74
Reputation: 133370
do the same with getAlias
<?php echo Html::img( Yii::getAlias('@root') .'/uploads/ring.jpg',
['class' => 'img-center', 'width'=>150, 'heigth'=>150, 'alt'=>'no image']) ?>
for debugging you can try creating a proper alias for your uploads directory
Yii::setAlias('@uploads', 'your_absolute_path_uploads');
var_dump( Url::to('@uploads') );
<?php echo Html::img( Yii::getAlias('@uploads') .'/ring.jpg',
['class' => 'img-center', 'width'=>150, 'heigth'=>150, 'alt'=>'no image']) ?>
if don't work ..be sure of your web server / apache / htaccess / redir configuration.
try using
use yii\helpers\Url;
<?php echo Html::img( Url::to['../../uploads/ring.jpg'],
['class' => 'img-center', 'width'=>150, 'heigth'=>150, 'alt'=>'no image']) ?>
Or set a proper absolute alias. This a sample for www.oracle.com .. but you should adapt to your need
Yii::setAlias('@oracle', 'http://www.oracle.com');
echo Url::to('@oracle'); // get URL from alias http://www.bsourcecode.com
Upvotes: 1