PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, January 28, 2022

[FIXED] Yii - not showing image path in the edit view

 January 28, 2022     php, yii     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing