I implemented CUploadedFile to upload images to my database but now when testing I am running into a couple of problems. I am having a really hard time tracking down the source of the problems. I have tried this in a couple of different environments of OSX and linux and the errors don’t change.
When I upload most files everything is just fine but when I try files larger than 1MB I often get one of the two errors below.
Failed to set unsafe attribute "uploadedFile".
Error while sending QUERY packet. PID=6429 //or some other number
Here is my code.
Controller:
public function actionUpload()
{...
$model->content = CUploadedFile::getInstance($this, 'content');
...
}
Model:
public function rules() {
return array(
array('uploadedFile', 'file', 'types'=>'jpg,JPG,png,PNG','allowEmpty'=>false,'maxSize'=>3242880,'wrongType'=>'jpg or png','tooLarge'=>'Smaller than 3MB'),
...
}
protected function beforeSave()
{
if($file=CUploadedFile::getInstance($this,'uploadedFile'))
{
$this->name=$file->name;
$this->type=$file->type;
$this->size=$file->size;
$this->content=file_get_contents($file->tempName);
}
return parent::beforeSave();
}
View:
<?php echo $form->fileField($model,'uploadedFile'); ?>
<?php echo $form->error($model,'uploadedFile'); ?>
php.ini:
upload_max_filesize = 5M