0

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: define filetype

How can I do that? Thanks a lot.

Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
arnold_p
  • 495
  • 6
  • 26

1 Answers1

0

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.

Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
  • hey, thanks for your answer, but it still not working. I use yiibooster `filefieldRow1`. can you help me with this? – arnold_p Mar 30 '14 at 11:22