Hi,
i’m trying to upload a file named uploaded_file with an android http request.
My environment is:
MAMP 2.1.1 with PHP 5.4.4 and Mountain Lion 10.8.3, MySQL database UTF8
If i use move_uploaded_file, everything works fine, but i want to use CUploadedFile.
My model Media is
class Media extends CActiveRecord
{
public $uploaded_file;
.....
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('Name, Title', 'length', 'max'=>500),
array('CreatedAt, LastEdit, Filename', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('ID, CreatedAt, LastEdit, Name, Title, Filename', 'safe', 'on'=>'search'),
array('uploaded_file', 'file', 'types'=>'jpg,jpeg,gif,png'),
);
}
...
}
and in the controller i have
public function actionUploadImage(){
...
$media = new Media;
$media->uploaded_file=CUploadedFile::getInstance($media,'uploaded_file');
...
}
but nothing is uploaded.
if i try
error_log($media->uploaded_file);
error_log($_FILES['uploaded_file']['name']);
i see the second one but the first is empty.
I’ve also tried to upload the file using a form
$form = $this->beginWidget(
'CActiveForm',
array(
'id' => 'upload-form',
'enableAjaxValidation' => false,
'htmlOptions' => array('enctype' => 'multipart/form-data'),
)
);
// ...
echo $form->labelEx($model, 'uno');
echo $form->fileField($model, 'uploaded_file');
echo $form->error($model, 'tre');
echo CHtml::submitButton('Carica');
$this->endWidget();
And it works.
Where am i wrong?
Thank you very much.
Giacomo