Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Bug Inserimento Dati Binari Su Sqlserver?

$
0
0
Salve a tutti,
devo conservare un file .html di tipo varbinary(MAX) su database sqlserver, ma ricevo un errore al salvataggio.
Per il codice mi sono rifatto a questo esempio: http://www.yiiframework.com/wiki/95/saving-files-to-a-blob-field-in-the-database/

E' un problema di codice o un bug?

Nella view ho:
'htmlOptions' => array('enctype' => 'multipart/form-data')


<?php echo $form->labelEx($model,'uploadedFile'); ?>
				<?php echo $form->fileField($model,'uploadedFile'); ?>
				<?php echo $form->error($model,'uploadedFile'); ?>

Nel controller:
$model->attributes=$_POST['InventarioPc'];
if($model->save()){
$model->descriz_html->saveAs( Yii::getPathOfAlias('backend.data.descrizpc') . DIRECTORY_SEPARATOR . $model->descriz_html_name);
$this->redirect(array('view','id'=>$model->id_postazione));
			}

Il model
public $uploadedFile;

public function rules()
	{

		return array(
array('uploadedFile', 'file', 'types'=>'html, htm'),
);
	}

public function beforeSave()
	{
		if($file=CUploadedFile::getInstance($this,'uploadedFile'))
		{
			
			$this->descriz_html_name = time() . "-" . $file->name;
			$this->descriz_html = file_get_contents($file->tempName);
			/*
			$this->descriz_html_type=$file->type;
			$this->descriz_html_size=$file->size;
			*/
			//$this->descriz_html=file_get_contents($file->tempName);
			
		}
	
		return parent::beforeSave();
	}


L'errore:
CDbException
throw new CDbException(Yii::t('yii','CDbCommand failed to execute the SQL statement: {error}',
if($model->save())


Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>