Yii Framework Forum: Upload Blob File To Database - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Upload Blob File To Database Rate Topic: -----

#1 User is offline   Lanka 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 20-August 14

Posted 22 August 2014 - 04:53 AM

Hi, :rolleyes:
This is my first time and I'm new for yii framework.
I want to store images in blob field of my database. I googled and tried. But I’ve had no luck. Every time I got error messages. I’m new for yii. So I can’t find the error also.. can anyone help me please..
0

#2 User is offline   Vilo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 10-March 14

Posted 22 August 2014 - 05:02 AM

View PostLanka, on 22 August 2014 - 04:53 AM, said:

Hi, :rolleyes:
This is my first time and I'm new for yii framework.
I want to store images in blob field of my database. I googled and tried. But I’ve had no luck. Every time I got error messages. I’m new for yii. So I can’t find the error also.. can anyone help me please..


Hello Lanka

Please read these wikies hope it'll help you. Saving files to a blob field in the database and Storing your images in your table's blob field and displaying that stored images.
The more you learn, the more you know.
The more you know, the more you forget.
The more you forget, the less you know.

-- Tomi Kaistila
0

#3 User is offline   Lanka 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 20-August 14

Posted 22 August 2014 - 05:37 AM

I tried for This . But it gives error "Property "CActiveForm.type" is not defined.".

This is my _form.

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'image-table-form',
	// Please note: When you enable ajax validation, make sure the corresponding
	// controller action is handling ajax validation correctly.
	// There is a call to performAjaxValidation() commented in generated controller code.
	// See class documentation of CActiveForm for details on this.
	'enableAjaxValidation'=>false,
	'method'=>'post',
    'type'=>'horizontal',
    'htmlOptions'=>array(
        'enctype'=>'multipart/form-data'
    )
)); ?>


This is my controller

public function actionUpdate($id)
	{
		$model=$this->loadModel($id);

		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);

		if(isset($_POST['ImageTable']))
		{
			$model->attributes=$_POST['ImageTable'];
			 if(!empty($_FILES['image_table']['tmp_name']['image']))
            {
                $file = CUploadedFile::getInstance($model,'image');
                $model->fileName = $file->name;
                $model->fileType = $file->type;
                $fp = fopen($file->tempName, 'r');
                $content = fread($fp, filesize($file->tempName));
                fclose($fp);
                $model->image = $content;
            }
 
            $model->user = Yii::app()->user->id;
			
			
			if($model->save())
				$this->redirect(array('view','id'=>$model->image_id));
		}

		$this->render('update',array(
			'model'=>$model,
			 'types'=>Type::model()->findAll()
		));
	}



this is my model

array('image', 'file', 
        'types'=>'jpg, gif, png, bmp, jpeg',
            'maxSize'=>1024 * 1024 * 10, // 10MB
                'tooLarge'=>'The file was larger than 10MB. Please upload a smaller file.',
            'allowEmpty' => true
         ),


Please help me...
0

#4 User is online   alirz23 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 988
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 22 August 2014 - 06:23 AM

there no type attribute on CActiveForm comment it out like so

<?php $form=$this->beginWidget('CActiveForm', array(
        'id'=>'image-table-form',
        // Please note: When you enable ajax validation, make sure the corresponding
        // controller action is handling ajax validation correctly.
        // There is a call to performAjaxValidation() commented in generated controller code.
        // See class documentation of CActiveForm for details on this.
        'enableAjaxValidation'=>false,
        'method'=>'post',
    // 'type'=>'horizontal', 
    'htmlOptions'=>array(
        'enctype'=>'multipart/form-data'
    )
)); ?>

0

#5 User is offline   Lanka 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 20-August 14

Posted 22 August 2014 - 10:23 PM

View Postalirz23, on 22 August 2014 - 06:23 AM, said:

there no type attribute on CActiveForm comment it out like so

<?php $form=$this->beginWidget('CActiveForm', array(
        'id'=>'image-table-form',
        // Please note: When you enable ajax validation, make sure the corresponding
        // controller action is handling ajax validation correctly.
        // There is a call to performAjaxValidation() commented in generated controller code.
        // See class documentation of CActiveForm for details on this.
        'enableAjaxValidation'=>false,
        'method'=>'post',
    // 'type'=>'horizontal', 
    'htmlOptions'=>array(
        'enctype'=>'multipart/form-data'
    )
)); ?>




I tried for that one.but when I click on submit button after selecting the image, it gives me another error "image cannot be blank".

Please help me.
0

#6 User is online   alirz23 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 988
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 23 August 2014 - 11:49 AM

sounds like a validation error
0

#7 User is offline   Lanka 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 20-August 14

Posted 24 August 2014 - 08:59 AM

View Postalirz23, on 23 August 2014 - 11:49 AM, said:

sounds like a validation error


So what can i do for it :(
0

#8 User is offline   Lanka 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 20-August 14

Posted 24 August 2014 - 11:38 PM

Finally i did it.. :D
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users