Hi there I am using this plugin to get files uploading but error is that file name is not being sent what i think because in controller it says index ‘image’ is not defined
here is view file
<div class="form">
<?php
$form=$this->beginWidget('CActiveForm', array(
'id'=>'topic-form',
'enableAjaxValidation'=>false,
'action' => Yii::app()->createUrl('hotel/UploadImages',array('id'=>$hotelId)),
'htmlOptions' => array('enctype' => 'multipart/form-data'), // ADD THIS
));
echo '<h1>Please select Images for hotel. (jpeg,jpg,gif,png)</h1>';
?>
<div id="asd"></div>
<?php
$this->widget('ext.jqrelcopy.JQRelcopy',
array(
'id' => 'copylink',
'removeText' => 'remove' //uncomment to add remove link
));
$x=0;
?>
<div class="row copy">
<?php
echo CHtml::label('Image Title',''); ?>
<?php echo CHtml::textField('HotelImages[title][]',''); ?>
<?php echo CHtml::FileField('HotelImages[image][]', ''); ?>
</div>
<a id="copylink" href="#" rel=".copy">Add another Image</a>
<div class="row buttons">
<?php echo CHtml::submitButton('Upload' ); ?>
</div>
<?php
$this->endWidget();
?>
</div>
Controller
public function actionUploadImages($id)
{
$model=new HotelImages;
if(isset($_POST['HotelImages']))
{
if( $this->saveImage($_POST['HotelImages'],$id) )
{
$this->redirect(array('location','id'=>$id));
}
}
$this->render('hotelPicture',array(
'$model'=>$model,
'hotelId'=>$id,
));
}
/*Get form data and save to database
*
*/
private function saveImage($formData,$id)
{
if ($formData === null)
return;
$result = array();
$idx=0;
//echo CVarDumper::dump ($formData);
//You will get 3 arrays in $formData: id, firstname, lastname
foreach($formData['title'] as $image)
{
try{
var_dump($formData);
$model = new HotelImages;
$model->title = $image;
$model->hotel_id = $id;
$model->image = CUploadedFile::getInstance($model, $formData['image']);
$file= dirname(Yii::app()->request->scriptFile) . DIRECTORY_SEPARATOR . $model->image->name;
$model->image->saveAs($file);
//The other attributes can be found at the same postion in the formData
//$model-> = $formData['lastname'][$idx];
//no id is submitted for new items
//if(!empty($formData['id'][$idx])
// $model->id= $formData['id'][$idx];
}
catch (Exception $c)
{
throw new CException('asd');
}
if(!$model->save())
return FALSE;
$idx++;
}
return true;
}
Dump of $_POST[‘HotelImages’]
array ( 'title' => array ( '0' => 'title' ) )
array
'title' =>
array
0 => string 'title' (length=5)
PROBLEM that there is no Image here and I cannot get image at line
$model->image = CUploadedFile::getInstance($model, $formData[‘image’]);