Yii, saving image from $ _FILES, but without using models

Is it possible? This is with the model.

CUploadedFile::getInstance($model,'newsimage'); $model->image->saveAs("image\path") 

but I don’t want to create a model to save my image.

What I really need is ... well, I'm trying to get CKEditor's "Upload Image" function to work, but I need a script to save the image. When I click on the “Download Image” button, I simply invoke the action, and from there I have access to the image that I selected using $_FILES , but I cannot save the file to the destination directory.

Is it possible to save the file to the target path (for example, C: \ myProject \ images) and not use the model?

EDIT:

Here is the solution I found a bit later. The download file is in $_FILES['upload'] , so ..

 $temp = CUploadedFile::getInstanceByName("upload"); // gets me the file into this variable ( i gues this wont work for multiple files at the same time ) $temp->saveAs("D:/games/" . $temp->name); // full name , including the filename too. 
+6
source share
1 answer

Assuming "no model" = "no db table"

You just do UploadForm.php, distributed from CFormModel in the models directory

 class UploadForm extends CFormModel { public $upload_file; public function rules() { return array( array('upload_file', 'file', 'types'=>'jpg,jpeg,gif,png','maxSize'=>10*1024*1024), ); } /** * Declares attribute labels. */ public function attributeLabels() { return array( 'upload_file'=>'Upload File', ); } } 

and in your controller

 $model->upload_file=CUploadedFile::getInstance($model,'upload_file'); $model->upload_file->saveAs("C:\myProject\images\".$model->upload_file->name) 
+8
source

Source: https://habr.com/ru/post/915681/


All Articles