PHP Snippet 1:
public function actionAjupd()
{
$this->getuser();
$model = new Allfiles();
// mb_internal_encoding( 'UTF-8' );
if ($model->load(Yii::$app->request->post())){
$x=$model->f_content;
$tmpfile=UploadedFile::getInstance($model, 'f_content');
$h=
(binary)(file_get_contents($tmpfile->tempName));
// var_dump($model);
$model->nomefile=basename($tmpfile);
$model->origine='S';
$model->estensione=pathinfo($tmpfile ,PATHINFO_EXTENSION);
$model->setAttribute('f_content','');
$model->save(false);
$id=$model->getPrimaryKey();
$connection = Yii::$app->getDb();
$command = $connection->createCommand("
update all_files set f_content=convert(
VARBINARY(max) ,
:contenuto ,1) where id=:id
",[':id'=>$id,':contenuto'=>'0x'.bin2hex($h)]);
$command->execute();
//\Yii::$app->response->format = Response::FORMAT_JSON;
return $this->redirect(Yii::$app->request->referrer ?: Yii::$app->homeUrl);
}
return $this->renderAjax('create', [
'model' => $model,
]);
}