我必须开发一个配置文件页面,其中显示了用户图像和一个更新按钮来更改配置文件图片。 在视图中显示图像和更新按钮如下所示
<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]) ?>
<?= Html::img($imgPath,['width'=>100,'height'=>100]);?>
<?= $form->field($model, 'imageFile')->fileInput(); ?>
<?= Html::submitButton('Update Profile Picture',['class'=>'btn btn-primary','id'=>'uploadButton']) ?>
<?php ActiveForm::end() ?>
使用fileInput我选择新文件并将其保存在服务器上,并显示以下行
$model->imageFile->saveAs('uploads/profilepictures/' . $session['user_name'] . '_profimg.' . $model->imageFile->extension);
该图像已成功上传到服务器(覆盖旧图像),但是当我刷新网页时,即使在服务器中用新图像替换了旧图像,也会显示该旧图像。 HTML :: img仍在获取较旧的图像,不确定为什么(以及从何处来?)。 有人请帮忙!