Issue
i am new for yii.i upload the image.image path go to the database.it is ok.when we update that details i need to show that path in my form but it is everytime display no file chosen.how to get correct image path..please anyone can help me?(i am used same file create and update one).
this is a my view file
<?php
echo $form->labelEx($model, 'document');
echo $form->fileField($model,'document',array('class'=>'span5','maxlength'=>500));
echo $form->error($model, 'document');
?>
Solution
You can show image like this:
<?php echo CHtml::image(Yii::app()->request->baseUrl.$model->document,"document"); ?>
If you want only path then do this:
<?php echo Yii::app()->request->baseUrl.$model->document; ?>
Then in update function use below code to update image if a new image is browsed.
$uploadedFile=CUploadedFile::getInstance($model,'document');
if($model->save())
{
if(!empty($uploadedFile)) // check if uploaded file is set or not
{
$uploadedFile->saveAs(Yii::app()->baseUrl.$model->document);
}
}
Answered By - NTkhan
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.