Yii Framework Forum: How To Get The Uploaded Image And Display - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How To Get The Uploaded Image And Display

#1 User is offline   SUBHASH 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 08-November 12

Posted 30 November 2012 - 02:23 AM

Here i am uploading the images into the seperate folder which is in application.protected.uploads but how get that image from the folder and display on the screen any help please here is my uploaded code


controller

$dir = Yii::getPathOfAlias('application.protected.uploads');
$uploaded = false;

$model = new Upload();

if (isset($_POST['Upload']))
{
$model->attributes = $_POST['Upload'];
$file = CUploadedFile::getInstance($model,'file');
if ($model->validate())
{
$uploaded = $file->saveAs($dir. '/' .$file->getName());
}
}


view :

<?php if ($uploaded): ?>
<p>File was uploaded. Check <?php echo $dir?> . </p>
<?php endif ?>

<?php echo CHtml::beginForm('','post',array
('enctype'=>'multipart/form-data'))?>
<?php echo CHtml::error($model, 'file')?>
<?php echo CHtml::activeFileField($model, 'file')?>
<?php echo CHtml::submitButton('Upload')?>
<?php echo CHtml::endForm()?>
0

#2 User is offline   Ravi Bhalodiya 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 27-August 12
  • Location:Gujarat India

Posted 06 April 2013 - 06:15 AM

echo $form->labelEx($model,'logo');
echo $form->fileField($model,'logo',array(),array('tabindex'=>13));


if(isset($model->logo))
{
echo CHtml::image(Yii::app()->controller->createUrl('site/loadImage/'.$model->logo), "No Image",array("width"=>"175px","height"=>"70px"));
}
Regards
Ravi Bhalodiya.
0

#3 User is offline   demay 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 24-August 12

Posted 18 May 2013 - 02:51 PM

did u get the solution? help me please
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users