getimagesize()在Yii2中无法正常工作

时间:2015-11-20 04:00:31

标签: php yii2 getimagesize

无法让此功能在我的控制器内部工作。它总是返回

getimagesize(/web/uploads/image1.jpg): failed to open stream: No such file or directory

这样称呼它:

$user->avatar = Yii::$app->getUrlManager()->getBaseUrl() . '/uploads/' . $model->avatar->baseName . '.' . $model->avatar->extension;   
getimagesize($user->avatar );  

任何解决方案?

显示从浏览器图像访问/web/uploads/image1.jpg。

1 个答案:

答案 0 :(得分:1)

- (void)initBarButton { UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleDone target:self action:@selector(cancel)]; self.navigationItem.leftBarButtonItem = cancelButton; UIBarButtonItem *updateButton = [[UIBarButtonItem alloc] initWithTitle:@"Update" style:UIBarButtonItemStyleDone target:self action:@selector(save)]; self.navigationItem.rightBarButtonItem = updateButton; } - (void)cancel { [self.navigationController popViewControllerAnimated:YES]; } 是本机PHP函数,与框架无关。您需要使用getimagesize指定完整图片路径,而不是basePathbaseUrl用于显示图片。

改为构建你的路径:

baseUrl

您还可以在use Yii; ... $imagePath = Yii::$app->basePath . '/web/uploads/' . $model->avatar->baseName . '.' . $model->avatar->extension; 文件中设置uploads文件夹的别名(此示例适用于高级应用):

bootstrap.php

然后要获得Yii::setAlias('uploads', dirname(dirname(__DIR__)) . '/frontend/web/uploads'); 文件夹的完整路径,您可以像这样引用它:

uploads