问题描述
您应该如何防止 CMultiFileUpload 小部件将所选文件的文件名附加到页面?
How are you supposed to prevent the CMultiFileUpload widget from appending the file names of selected files to the page?
这是我的代码:
<?php
$this->widget('CMultiFileUpload', array(
'name' => 'images',
'accept' => 'jpeg|jpg|gif|png',
'denied' => 'Invalid file type',
'htmlOptions' => array('multiple'=>'multiple'),
));?>
这是我正在谈论的图片:
Here is a picture of what I am talking about:
我需要删除箭头所指的内容.当事实并非如此时,为什么它会显示未选择文件"也很奇怪.如果我提交表单,文件确实会发送到服务器.
I need to remove what the arrows point to. It's also strange why it says "No files selected" when that isn't the case. If I submit the form, the file does indeed get sent to the server.
如果 javascript 关闭,它会做我想要的.它还修复了未选择文件"错误.有没有办法只为小部件禁用 javascript?
It does what I want if javascript is turned off though. It also fixes the "no files selected" error. Is there a way to disable the javascript for just the widget?
推荐答案
如果您想隐藏已上传文件的名称,则可以使用 CMultiFIleUpload 中的 options例如:-
if you want to hide the names of the files you have uploaded then you can use the options in your CMultiFIleUploadeg:-
<?php
$this->widget('CMultiFileUpload', array(
'name' => 'images',
'accept' => 'jpeg|jpg|gif|png',
'denied' => 'Invalid file type',
'htmlOptions' => array('multiple'=>'multiple'),
'options'=>array(
'onFileAppend'=>'
function(e,v,m)
{
// try using e.preventDefault();
(".MultiFile-label").css("display","none");
}
'
)
));?>
注意:- 我还没有测试过,但希望它有所帮助.
Note:- I haven't tested it but hope it helps.
这篇关于yii CMultiFileUpload 停止默认行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!