当前位置: 首页>>代码示例>>PHP>>正文


PHP UploadedFile::getInstances方法代码示例

本文整理汇总了PHP中yii\web\UploadedFile::getInstances方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadedFile::getInstances方法的具体用法?PHP UploadedFile::getInstances怎么用?PHP UploadedFile::getInstances使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\web\UploadedFile的用法示例。


在下文中一共展示了UploadedFile::getInstances方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionCreate

 /**
  * Creates a new Sucursal model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Sucursal();
     $model->create_user = Yii::$app->user->getId();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $saved = true;
         $model->imagenes = UploadedFile::getInstances($model, 'imagenes');
         foreach ($model->imagenes as $imagen) {
             $image = new Imagen();
             $rnd = rand(0, 99999999);
             $path = Yii::$app->basePath . '/web/images';
             if (!file_exists($path)) {
                 mkdir($path, 0777);
             }
             $path = $path . '/Sucursal';
             if (!file_exists($path)) {
                 mkdir($path, 0777);
             }
             $path = $path . '/' . $model->id;
             if (!file_exists($path)) {
                 mkdir($path, 0777);
             }
             $imagen->saveAs($path . '/' . $rnd . '.' . $imagen->extension);
             $image->ur_imagen = $rnd . '.' . $imagen->extension;
             $image->save();
         }
         if ($saved) {
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
开发者ID:EC-System,项目名称:SantasAlitas,代码行数:38,代码来源:SucursalController.php

示例2: actionIndex

 public function actionIndex($id, $tagId = null)
 {
     $project = $this->loadModel('app\\models\\Project', $id);
     $this->view->params['appSettings'] = ['app_name' => $project->title];
     if (!\Yii::$app->user->can('viewProject', ['project' => $project])) {
         throw new ForbiddenHttpException('Access denied');
     }
     $model = new Files();
     if (($files = UploadedFile::getInstances($model, 'file')) && !\Yii::$app->user->isGuest) {
         foreach ($files as $file) {
             $model = new Files();
             $model->file = $file->name;
             $model->project_id = $project->id;
             $model->tags = $_POST['Files']['tags'];
             if ($model->save()) {
                 $file->saveAs($this->_getFolder($model) . $file->name);
             } else {
                 die(var_dump($file->getErrors()));
             }
         }
     }
     $searchModel = new FilesSearch();
     $searchModel->project_id = (int) $project->id;
     if (isset($tagId)) {
         $searchModel->tagId = $tagId;
     }
     $dataProvider = $searchModel->search(\Yii::$app->request->queryParams);
     $model->tags = null;
     return $this->render('index', ['model' => $model, 'dataProvider' => $dataProvider, 'searchModel' => $searchModel, 'project' => $project, 'tagId' => $tagId]);
 }
开发者ID:mops1k,项目名称:yiimine,代码行数:30,代码来源:FilesController.php

示例3: beforeSave

 /**
  * Upload Files Before Save.
  *
  * @return void
  * @version 1.0
  */
 public function beforeSave()
 {
     $result = [];
     //Array of Images data.
     $owner = $this->owner;
     // If attributes are not empty.
     if ($this->attributes) {
         foreach ($this->attributes as $attr) {
             // If Isset attribute in our Model.
             if (isset($owner->{$attr['attribute']}) && ($path = $this->getPath($attr))) {
                 $files = UploadedFile::getInstances($owner, $attr['attribute']);
                 // If array with files is not empty.
                 if ($files) {
                     foreach ($files as $key => $file) {
                         $url = Url::to($path . DIRECTORY_SEPARATOR . $file->name);
                         if ($file->saveAs($url)) {
                             $result[$attr['attribute']][$key] = ['url' => $url, 'file' => $file];
                             // If it is image then crop it.
                             if (getimagesize($url) && isset($attr['sizes'])) {
                                 $result[$attr['attribute']][$key]['cropped'][] = $this->crop($attr, $file, Url::to($path));
                             }
                         }
                     }
                     $this->owner->{$attr['attribute']} = $result[$attr['attribute']];
                 }
             }
         }
     }
 }
开发者ID:aliashenko-corp-web4pro,项目名称:yii2uploadbehavior,代码行数:35,代码来源:UploadFilesBehavior.php

示例4: actionUpload

 public function actionUpload()
 {
     $model = new UploadForm();
     $model->file = UploadedFile::getInstances($model, 'file');
     if ($model->rules()[0]['maxFiles'] == 1 && sizeof($model->file) == 1) {
         $model->file = $model->file[0];
     }
     if ($model->file && $model->validate()) {
         $result['uploadedFiles'] = [];
         if (is_array($model->file)) {
             foreach ($model->file as $file) {
                 $path = $this->getModule()->getUserDirPath() . DIRECTORY_SEPARATOR . $file->name;
                 $file->saveAs($path);
                 $result['uploadedFiles'][] = $file->name;
             }
         } else {
             $path = $this->getModule()->getUserDirPath() . DIRECTORY_SEPARATOR . $model->file->name;
             $model->file->saveAs($path);
             $result['uploadedFiles'][] = $model->file->name;
         }
         Yii::$app->response->format = Response::FORMAT_JSON;
         return $result;
     } else {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ['error' => $model->getErrors('file')];
     }
 }
开发者ID:nemmo,项目名称:yii2-attachments,代码行数:27,代码来源:FileController.php

示例5: actionUpdate

 /**
  * Updates an existing Product model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post())) {
         $model->image = UploadedFile::getInstance($model, 'image');
         $model->images = UploadedFile::getInstances($model, 'images');
         if ($model->validate() && $model->save()) {
             $dir = Yii::getAlias('@frontend/web/uploads/product/' . $model->id);
             if ($model->image) {
                 $model->image->saveAs($dir . '/main.jpg');
             }
             if ($model->images) {
                 $imageModels = Image::findAll(['model_id' => $model->id]);
                 if ($imageModels) {
                     foreach ($imageModels as $image) {
                         $file = $dir . '/' . $image->id . '.jpg';
                         if (file_exists($file)) {
                             unlink($file);
                         }
                         $image->delete();
                     }
                 }
                 foreach ($model->images as $image) {
                     $imageModel = new Image();
                     $imageModel->model_id = $model->id;
                     $imageModel->save();
                     $image->saveAs($dir . '/' . $imageModel->id . '.jpg');
                 }
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     }
     return $this->render('update', ['model' => $model]);
 }
开发者ID:cyanofresh,项目名称:yii2shop,代码行数:40,代码来源:ProductController.php

示例6: actionCreate

 /**
  * Creates a new File model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new File();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $dir = Yii::getAlias('@app/uf');
         foreach (UploadedFile::getInstances($model, 'files') as $file) {
             $file->saveAs($dir . '/' . $file->baseName . '.' . $file->extension);
             $new_file = new File();
             $new_file->setAttributes($model->attributes);
             $new_file->file_name = $file->baseName . '.' . $file->extension;
             $new_file->file_path = $dir . '/' . $file->baseName . '.' . $file->extension;
             $new_file->table_name = 'person';
             $new_file->class_name = Person::className();
             $new_file->save();
         }
         Yii::$app->getSession()->addFlash('success', "Запись \"{$model->id}\" успешно добавлена.");
         return $this->redirect(Url::previous() != Yii::$app->homeUrl ? Url::previous() : ['view', 'id' => $model->id]);
     } else {
         if (Yii::$app->request->referrer != Yii::$app->request->absoluteUrl) {
             Url::remember(Yii::$app->request->referrer ? Yii::$app->request->referrer : null);
         }
         if (!Yii::$app->request->isPost) {
             $model->setAttributes(Yii::$app->request->get());
         }
         return $this->render('create', ['model' => $model]);
     }
 }
开发者ID:slavam,项目名称:placement,代码行数:32,代码来源:FileController.php

示例7: actionStudentInfo

 public function actionStudentInfo()
 {
     $user = new User();
     $model = new Student();
     $model1 = new Type();
     $region = new Region();
     $file = new UploadForm();
     //兼职的分类
     $typeInfo = $model1->getTypes();
     //获取省
     $parentOne = $region->getParentOne();
     if (Yii::$app->request->isPost) {
         $request = \YII::$app->request;
         $post = $request->post();
         $file->student_file = UploadedFile::getInstances($file, 'student_file');
         foreach ($file->student_file as $v) {
             $path = 'uploads/' . time() . rand('111', '999') . '.' . $v->extension;
             $v->saveAs($path);
             $imgUrl[] = $path;
         }
         $model->addStudent($imgUrl, $post);
     }
     $userInfo = $user->getUser(1);
     //用户信息
     return $this->render('studentinfo', ['model' => $model, 'typeInfo' => $typeInfo, 'file' => $file, 'parentOne' => $parentOne, 'userInfo' => $userInfo]);
 }
开发者ID:wangpengzhen,项目名称:web,代码行数:26,代码来源:UserController.php

示例8: actionUpload

 public function actionUpload()
 {
     $model = new UploadForm();
     if (Yii::$app->request->isPost) {
         $model->file = UploadedFile::getInstances($model, 'file');
         if ($model->file && $model->validate()) {
             foreach ($model->file as $file) {
                 $model_script = new Sqlscript();
                 $save_name = '';
                 if (strtolower($file->extension) === 'txt' || strtolower($file->extension) === 'sql') {
                     $path = \Yii::getAlias('@webroot') . "/scripts/";
                     $fname = iconv('UTF-8', 'tis-620', $file->name);
                     // win
                     $save_name = $path . $fname;
                     $file->saveAs($save_name);
                     $model_script->topic = iconv('tis-620', 'UTF-8', $fname);
                     $model_script->sql_script = iconv('tis-620', 'UTF-8', file_get_contents($save_name));
                     $model_script->user = Yii::$app->user->identity->username;
                     $model_script->d_update = date('Y-m-d H:i:s');
                 }
                 $model_script->save();
             }
             return $this->redirect(['sqlscript/index']);
         }
     }
     return $this->render('upload', ['model' => $model]);
 }
开发者ID:WittayaSi,项目名称:qofdhdc,代码行数:27,代码来源:SqlscriptController.php

示例9: actionUpload

 public function actionUpload()
 {
     if (Yii::$app->request->isPost) {
         $post = Yii::$app->request->post();
         $slider = Slider::findOne($post['sliderId']);
         $form = new ImageUploadForm();
         $images = UploadedFile::getInstances($form, 'images');
         foreach ($images as $k => $image) {
             $_model = new ImageUploadForm();
             $_model->image = $image;
             if ($_model->validate()) {
                 $path = \Yii::getAlias('@uploadsBasePath') . "/img/{$_model->image->baseName}.{$_model->image->extension}";
                 $_model->image->saveAs($path);
                 // Attach image to model
                 $slider->attachImage($path);
             } else {
                 foreach ($_model->getErrors('image') as $error) {
                     $slider->addError('image', $error);
                 }
             }
         }
         if ($form->hasErrors('image')) {
             $form->addError('image', count($form->getErrors('image')) . ' of ' . count($images) . ' images not uploaded');
         } else {
             Yii::$app->session->setFlash('image-success', Yii::t('app', 'Images successfully uploaded', ['Image' => Yii::t('app', 'Image'), 'images' => Yii::t('app', 'images'), 'n' => count($images)]));
         }
         return $this->redirect(['index?sliderId=' . $post['sliderId']]);
     }
 }
开发者ID:highestgoodlikewater,项目名称:yii2-cms-sliders,代码行数:29,代码来源:ImagesController.php

示例10: actionCreate

 /**
  * Creates a new Photos model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Photos();
     if ($model->load(Yii::$app->request->post())) {
         $model->shared_with = implode(',', $model->shared_with);
         $file = UploadedFile::getInstances($model, 'filename');
         foreach ($file as $filename) {
             $model1 = new Photos();
             $model1->user_id = Yii::$app->user->id;
             $model1->shared_with = $model->shared_with;
             $model1->filename = date("Ymdhis") . $filename->name;
             $path = Yii::getAlias('@uploads/albums/' . $model1->filename);
             if ($model1->save()) {
                 $filename->saveAs($path);
                 Image::thumbnail($path, 120, 120)->save(Yii::getAlias('@uploads/albums/thumbs/' . $model1->filename), ['quality' => 50]);
             }
         }
         Yii::$app->session->setFlash('success', 'Photos successfully posted.');
         Yii::$app->notification->notify($model1->filename, $model1, $model1->user, Yii::$app->controller->id, $model1->shared_with);
         $this->redirect('index');
     } else {
         if (Yii::$app->request->isAjax) {
             return $this->renderAjax('_form', ['model' => $model]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     }
 }
开发者ID:livingdreams,项目名称:kidcrossing,代码行数:33,代码来源:PhotosController.php

示例11: load

 /**
  * @inheritdoc
  */
 protected function load($model, $request)
 {
     if ($result = parent::load($model, $request)) {
         $model->uploadedFiles = \yii\web\UploadedFile::getInstances($model, 'uploadedFiles');
     }
     return $result;
 }
开发者ID:heartshare,项目名称:yii2-sync,代码行数:10,代码来源:TransactionUpdateAction.php

示例12: actionUpdate

 /**
  * Updates an existing DotaPlayer model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if (Yii::$app->request->isPost) {
     }
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $model->imageFiles = UploadedFile::getInstances($model, 'imageFiles');
         //echo'<pre>';var_dump($model->imageFiles);echo'</pre>';die;
         if (count($model->imageFiles) != 0) {
             if ($model->upload()) {
                 $img_path = $model->path . '/' . $model->filename;
                 $img_dimentions = DImageHelper::getImageDimentions($img_path);
                 DImageHelper::processImage($model->path, $model->filename, 250, 250, $img_dimentions, true);
                 $model->foto = $model->filename;
             }
             $model->imageFiles = null;
         }
         //echo'<pre>';print_r($model);echo'</pre>';//die;
         if ($model->foto != $model->oldAttributes['foto'] && $model->oldAttributes['foto'] != '') {
             DFileHelper::deleteFile($model->oldAttributes['foto'], 'players');
         }
         $model->save(false);
         if (isset($_POST['save'])) {
             return $this->redirect(['index']);
         } else {
             return $this->redirect(['update', 'id' => $model->account_id]);
         }
     } else {
         //echo'<pre>';print_r($_FILES);echo'</pre>';//die;
         //echo'<pre>';print_r($model);echo'</pre>';die;
         return $this->render('update', ['model' => $model]);
     }
 }
开发者ID:aldegtyarev,项目名称:fantasy,代码行数:39,代码来源:DotaPlayerController.php

示例13: actionCreate

 /**
  * Creates a new Tweet model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Tweet();
     if ($model->load(Yii::$app->request->post())) {
         $model->owner = Yii::$app->user->identity->username;
         $date = new \DateTime();
         $model->timestamp = $date->getTimestamp();
         if ($model->save()) {
             //Upload images if need be.
             $image = UploadedFile::getInstances($model, 'image');
             \Cloudinary::config(array("cloud_name" => "dxqmggd5a", "api_key" => "314154111631994", "api_secret" => "KE-AgYwX8ecm8N2omI22RDVmFv4"));
             foreach ($image as $file) {
                 $uploadResult = \Cloudinary\Uploader::upload($file->tempName);
                 $myConnection = new MediaConnections();
                 $myConnection->tweet = $model->id;
                 $myConnection->url = $uploadResult['url'];
                 $myConnection->timestamp = $model->timestamp;
                 $myConnection->save();
             }
             User::findByUsername($model->owner)->createTweet();
             return $this->redirect(Yii::$app->request->referrer);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
开发者ID:bryantmakesprog,项目名称:TwitterClone,代码行数:30,代码来源:TweetController.php

示例14: signup

 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         $user->mobile = $this->mobile;
         $user->user_extra1 = $this->user_extra1;
         //上传用户信息图片, 多文件上传, 最多2张图
         $tmpStr2 = "";
         $this->files = UploadedFile::getInstances($this, 'files');
         foreach ($this->files as $file) {
             //$user->files = UploadedFile::getInstances($user, 'files');
             //foreach ($user->files as $file)
             //{
             $targetFileId = date("YmdHis") . '-' . uniqid();
             $ext = pathinfo($file->name, PATHINFO_EXTENSION);
             $targetFileName = "{$targetFileId}.{$ext}";
             $targetFile = Yii::getAlias('@webroot') . DIRECTORY_SEPARATOR . SignupForm::PHOTO_PATH . DIRECTORY_SEPARATOR . $targetFileName;
             $file->saveAs($targetFile);
             //$tmpStr2 =  $tmpStr2 . "{$targetFile};";
             $tmpStr2 = $tmpStr2 . "/user/photo/{$targetFileName};";
         }
         $user->user_extra2 = $tmpStr2;
         if ($user->save()) {
             return $user;
         }
     }
     return null;
 }
开发者ID:hehbhehb,项目名称:hongsong,代码行数:37,代码来源:SignupForm.php

示例15: actionView

 public function actionView($id)
 {
     $model = tblGallery::findOne($id);
     if ($model->load($_POST)) {
         $files = \yii\web\UploadedFile::getInstances($model, 'upload_files');
         if (isset($files) && count($files) > 0) {
             $mPath = \Yii::getAlias('@webroot') . '/images/gallery/cat_' . $id;
             if (!is_dir($mPath)) {
                 mkdir($mPath);
                 chmod($mPath, '777');
             }
             foreach ($files as $file) {
                 $mPic = 'nkc_' . substr(number_format(time() * rand(), 0, '', ''), 0, 14) . '.' . $file->extension;
                 //Upload Images
                 if ($file->saveAs($mPath . '/' . $mPic)) {
                     $image = \Yii::$app->image->load($mPath . '/' . $mPic);
                     $image->resize(1024, 1024);
                     $image->save($mPath . '/' . $mPic);
                     //resize images thumb
                     $image = \Yii::$app->image->load($mPath . '/' . $mPic);
                     $image->resize(250, 250);
                     $mThumb = $mPath . '/thumb/';
                     if (!is_dir($mThumb)) {
                         mkdir($mThumb);
                         chmod($mThumb, '777');
                     }
                     $image->save($mThumb . $mPic);
                 }
             }
         }
     }
     return $this->render('view', ['model' => $model]);
 }
开发者ID:jatuponp,项目名称:iweb,代码行数:33,代码来源:GalleryController.php


注:本文中的yii\web\UploadedFile::getInstances方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。