Hi all
I see this is a topic that has been writen about - sorry I still need help as a newbie
I have tried to follow the instructions given in the documentation but I seem to do something wrong.
I work on the following table:
CREATE TABLE IF NOT EXISTS `l_link` (
`l_id` int(11) NOT NULL AUTO_INCREMENT,
`l_link` varchar(100) NOT NULL,
`l_short` varchar(15) NOT NULL,
`l_long` varchar(45) NOT NULL,
`l_img` blob,
`l_sequence` int(11) NOT NULL,
PRIMARY KEY (`l_id`),
UNIQUE KEY `l_id_UNIQUE` (`l_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=72 ;
I generated model and crud for this.
To my model (LLink.php) I added
class Candidate extends CActiveRecord
{
/**
* Property for receiving the file from the form
* It should be different from any other field in the database
*/
public $l_img;
public function rules()
{
return array(
array('l_img', 'file', 'types'=>'jpg, gif, png'),
);
}
/**
* Saves data of the uploaded file
*/
public function beforeSave()
{
if($file=CUploadedFile::getInstance($this,'l_img'))
{
$this->l_img=file_get_contents($file->tempName);
}
return parent::beforeSave();
}
}
I didn’t change the controller (LLinkController.php) but changed this in view _form:
<div class="row">
<?php echo $form->labelEx($model,'l_img'); ?>
<?php echo $form->fileField($model,'l_img'); ?>
<?php echo $form->error($model,'l_img'); ?>
</div>
So now when I insert or update a column the contents of my field l_img is only a couple of bytes with what seems to be the filename…
What is wrog? Is my problem that I don’t store the filename and extension?