Hi…I really need some help, as nothing on the net refers to my specific situation.
I am using the wizard-behavior extension. It is built using CFormModel rather than CActiveRecord Model. I am pretty much stuck using things the way they are setup…so…
I have a 4 step registration form, first 3 steps are fine, however, the 4th page is to upload a photo. I can not pass the image file to the controller.
Here is my Model:
<?php
class UploadPhoto extends CFormModel {
public $userPhoto;
public function rules() {
return array(
array('$userPhoto','file','types'=>'jpg,jpeg,gif','allowEmpty'=>false),
);
}
public function attributeLabels() {
return array(
'$userPhoto'=>'Upload A Photo',
);
}
public function getForm()
{
return new CForm(array(
'showErrorSummary'=>false,
'enctype'=>'multipart/form-data',
'elements'=>array(
'$userPhoto'=>array(
'type'=>'file',
'hint'=>'Please Choose One',
),
),
'buttons'=>array(
'reset'=>array(
'type'=>'submit',
'label'=>'Reset Form'
),
'submit'=>array(
'type'=>'submit',
'label'=>'Next',
)
)
), $this);
}
}
And my form
<?php
echo $event->sender->menu->run();
echo '<div>Step '.$event->sender->currentStep.' of '.$event->sender->stepCount;
echo '<h3>'.$event->sender->getStepLabel($event->step).'</h3>';
echo CHtml::tag('div',array('class'=>'form'),$form);
And my controller
<?php
class DemoController extends CController {
public function beforeAction($action) {
$config = array();
switch ($action->id) {
case 'registration':
$config = array(
'steps'=>array('Identity', 'ContactDetails', 'UploadPhoto'),
'events'=>array(
'onStart'=>'wizardStart',
'onProcessStep'=>'registrationWizardProcessStep',
'onFinished'=>'wizardFinished',
'onInvalidStep'=>'wizardInvalidStep',
'onSaveDraft'=>'wizardSaveDraft'
),
'menuLastItem'=>'Register'
);
//more codes here
//more codes here
//more codes here
//more codes here
//more codes here
public function wizardFinished($event) {
$command = Yii::app()->db->createCommand();
if(isset($event->data['Identity']))
{
$db_array = array_merge($event->data['Identity']);
$command->insert('identity',$db_array);
}
if(isset($event->data['ContactDetails']))
{
$db_array = array_merge($event->data['ContactDetails']);
$command->insert('contactdetails',$db_array);
}
//this statement is to insert the image name into the table called uploadphoto
if(isset($event->data['UploadPhhoto']))
{
$db_array = array_merge($event->data['UploadPhhoto']);
$command->insert('uploadphoto',$db_array);
}
$this->UploadPhoto($db_array['userPhoto']);
$db_array['inPhoto']=$_SESSION['newName'];
if ($event->step===true){
$command->insert('users',$db_array);
// ...redirect to another page
$this->render('completed', compact('event'));
}else{
$this->render('finished', compact('event'));
}
$event->sender->reset();
Yii::app()->end();
}
public function UploadPhoto($userPhoto){
Yii::import('application.extensions.upload.Upload');
// receive file from post
//$Upload = new Upload( (isset($inPhoto) ? $inPhoto : null) );
//$fullpath = 'C:/Users/Pirificio/Pictures/'.$inPhoto; //Used to test locally
$Upload = new Upload( (isset($userPhoto) ? $userPhoto : null) );
$Upload->jpeg_quality = 100;
$Upload->no_script = false;
$Upload->image_resize = true;
$Upload->image_x = 700;
$Upload->image_y = 500;
$Upload->image_ratio = true;
// some vars
$newName = md5($userPhoto);
$destPath = Yii::app()->getBasePath().'/../images/members/';
$destName = 'big';
// verify if was uploaded
if ($Upload->uploaded) {
$Upload->file_new_name_body = $newName;
$Upload->process($destPath);
// if was processed
if ($Upload->processed) {
$destName = $Upload->file_dst_name;
// create the thumb
unset($Upload);
$destName = 'small';
$Upload = new Upload($destPath.$destName);
$Upload->file_new_name_body = $newName;
$Upload->no_script = false;
$Upload->image_resize = true;
$Upload->image_x = 120;
$Upload->image_y = 80;
$Upload->image_ratio = true;
$Upload->process($destPath);
} else {
echo($Upload->error);
};
};
$_SESSION['newName']=$newName;
return;
}
}
}
}
Problem is, the image isn’t uploaded nor even the name stored to db like everything else is. Am using an extension called ‘upload’ used to upload photos. If there is another way to approach it, please advice me
HELP Please!!!
Demay