如何在Yii fileField中显示值(“路径”)?

问题描述 投票:0回答:1

我想显示已存储在DB中的已上传文件的路径。如何显示此路径而不是默认消息“未选择文件”。

enter image description here

我有一个textField,其中路径wos在更新操作时加载。现在我已将textField更改为fileFiled,但我希望用户可以看到已上传文件的路径。

enter image description here

我可以在fileField $ htmlOptions中添加一些内容来显示此路径吗?

<div class="control-group">
    <?= $form->labelEx($model, 'path_to_logo', array('class' => 'control-label')); ?>
    <div class="controls">
        <?= $form->fileField($model, 'path_to_logo', array('class' => 'span12')); ?>
        <?= $form->error($model, 'path_to_logo'); ?>
    </div>
</div>

更新:我希望在文件路径已经存在时产生这种效果:enter image description here

php html yii
1个回答
1
投票

由于安全原因,无法设置文件字段值。见How to set a value to a file input in HTML?

如果要显示当前路径,则应单独输出它是<span或其他HTML元素。

© www.soinside.com 2019 - 2024. All rights reserved.