This question already has an answer here:
everyone I have an upload system in my web application, I have defined filetype rules to allow: .pdf, .xls, .xlsx, .doc, .docx, .ppt, and .pptx in /models/File.php Here is my code:
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('nama_file, id_kategori', 'required'),
array('nama_file', 'length', 'max'=>100),
array('nama_file', 'file', 'types'=>'pdf, xls, xslx, doc, docx, ppt, pptx, ppsx', 'maxSize'=>50 * 1024 * 1024, 'tooLarge'=>'File tidak boleh lebih dari 50 Megabytes'),
array('id_user, id_kategori', 'length', 'max'=>11),
array('deskripsi', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id_file, nama_file, deskripsi, id_user, id_kategori, tgl_post', 'safe', 'on'=>'search'),
);
}
I want in my web application when I upload a file, the browse dialog box show those filetypes I have defined:
How can I do that? Thanks a lot.
</div>
Setting mine types on your file field will help filter the files user can pick.
<div class="row">
<?= $form->labelEx($model, 'nama_file'); ?>
<?= $form->fileField($model, 'nama_file', array('accept' =>
'application/ms*,application/vnd*,application/pdf')); ?>
<?= $form->error($model, 'nama_file'); ?>
</div>
However, Google Chrome will not display the file types, but "Custom Files". You can not change this implementation.