Filefield Update

Hello everyone,

        I have used fileField for browse the file from client's system. So my code is :

                [b]<?php echo $form->fileField($model, 'music_file'); ?> [/b]

when I create a new record, it is working fine, also stores the uploaded file name in Database and also copy the file in server also. But when I press on Update button, the field is blank, not displaying name of stored file name from Database. I want to display name of stored file name from the Database. Eagerly waiting for your response.

Thanks in Advance!!!!!

You can’t specify the content of a file input in HTML. You’ll need to display the name separately.

<? if ($model->music_file): ?>

    <div>Existing file: <?php echo CHtml::encode($model->music_file); ?></div>

<? endif; ?>

<?php echo $form->fileField($model, 'music_file'); ?> 

This assumes that the music_file file stores the name. If not, just use the relevant field.

Thanks for your reply. But suppose we use Textfield at that time in Update it directly takes stored value from the Database. Such a way, I want to create a field in which it gives directly stored file name.


You can’t; it’s a limitation (actually a security feature) of HTML. The file field input can only be populated by user action. See here.