how upload files using external action?
I want to upload files along with other form like the captcha declared as external action in sitecontroller used in contact form… help me thanks…
how upload files using external action?
I want to upload files along with other form like the captcha declared as external action in sitecontroller used in contact form… help me thanks…
Dear FRIEND
The following is a very primitive implementation.
TrialController.php
class TrialController extends Controller
{
public function actions()
{
return array(
'upload'=>array(
'class'=>'UploadAction',
),
);
}
protected/components/UploadAction.php
class UploadAction extends CAction{
public function run(){
$image=CUploadedFile::getInstanceByName('image');
if(isset($image)){
$image->saveAs('images/'.$image->name);
//Do some other stuff...
//Redirect somewhere...
}
$this->controller->render("_form");
}
}
protected/views/trial/_form.php.
<?php echo CHtml::beginForm('','post',array('enctype'=>'multipart/form-data'));?>
<p>Upload your image here.</p>
<?php echo CHtml::fileField('image');?>
<?php echo CHtml::submitButton('Upload');?>
<?php echo CHtml::endForm();?>
I hope it would help a bit.