Yii Framework Forum: About image upload in Yii 1.1.1 - Yii Framework Forum

Jump to content

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

About image upload in Yii 1.1.1 Rate Topic: -----

#1 User is offline   heamon 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 15-March 10
  • Location:Beijing.China

Posted 16 March 2010 - 01:11 AM

When I use CActiveForm to upload photo, write the form like
<div class="row">
<?php echo $form->labelEx($model,'product_img'); ?>
<?php echo $form->fileField($model, 'product_image', array('id'=>'product_image')); ?>
<?php echo $form->error($model,'product_img'); ?>

</div>

In controller use $_FILES['product_img'] to get the file, but it always said there's no index of product_img

Any helper is welcome!
0

#2 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 16 March 2010 - 01:14 AM

Do

var_dump($_FILES);


and see what's set.
0

#3 User is offline   heamon 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 15-March 10
  • Location:Beijing.China

Posted 16 March 2010 - 01:21 AM

View PostY!!, on 16 March 2010 - 01:14 AM, said:

Do

var_dump($_FILES);


and see what's set.



Here's var_dump got:
array(1) {
["product"]=>
array(5) {
["name"]=>
array(1) {
["product_img"]=>
string(21) "sports_zone_large.png"
}
["type"]=>
array(1) {
["product_img"]=>
string(9) "image/png"
}
["tmp_name"]=>
array(1) {
["product_img"]=>
string(14) "/tmp/phpXvBHtq"
}
["error"]=>
array(1) {
["product_img"]=>
int(0)
}
["size"]=>
array(1) {
["product_img"]=>
int(691)
}
}
}

But why each item stored with array, and when use upload extension, it always said can't use a array like in trim or strtolower
0

#4 User is offline   mech7 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 220
  • Joined: 26-March 09

Posted 16 March 2010 - 02:09 AM

In your model (or controller )you can access it like:

$this->pdf = CUploadedFile::getInstance($this, 'pdf');
$this->pdf->saveAs($new_pdf);
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