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


PHP CUploadedFile::getInstancesByName方法代码示例

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


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

示例1: actionCreate

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Photo();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Photo'])) {
         $model->attributes = $_POST['Photo'];
         if (isset($_FILES['images']['name'][0]) && $_FILES['images']['name'][0] !== '') {
             $model->name = 'new';
         }
         if ($model->validate()) {
             $images = CUploadedFile::getInstancesByName('images');
             foreach ($images as $image) {
                 $imageModel = new Photo();
                 $name = uniqid() . $image->name;
                 $image->saveAs(Yii::getPathOfAlias('webroot.uploads.images') . DIRECTORY_SEPARATOR . $name);
                 copy(Yii::getPathOfAlias('webroot.uploads.images') . DIRECTORY_SEPARATOR . $name, Yii::getPathOfAlias('webroot.uploads.images') . DIRECTORY_SEPARATOR . 'thumbs' . DIRECTORY_SEPARATOR . $name);
                 $thumb = Yii::app()->image->load(Yii::getPathOfAlias('webroot.uploads.images') . DIRECTORY_SEPARATOR . 'thumbs' . DIRECTORY_SEPARATOR . $name);
                 $thumb->resize(300, 300);
                 $thumb->save();
                 $imageModel->name = $name;
                 $imageModel->category_id = $_POST['Photo']['category_id'];
                 $imageModel->save();
             }
             Yii::app()->user->setFlash('success', Yii::t('main', 'Данные успешно сохранены!'));
             $this->refresh();
         } else {
             Yii::app()->user->setFlash('error', Yii::t('main', 'Ошибка!'));
         }
     }
     $this->render('create', array('model' => $model));
 }
开发者ID:Vladimirtishenko,项目名称:val.ua,代码行数:36,代码来源:PhotoController.php

示例2: actionCreate

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new gRecruitment();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['gRecruitment'])) {
         $model->attributes = $_POST['gRecruitment'];
         $model->followup_id = 1;
         $model->final_result_id = 1;
         $model->image = CUploadedFile::getInstance($model, 'image');
         $docs = CUploadedFile::getInstancesByName('docs');
         if (isset($model->image)) {
             $model->photo_path = $model->image->name;
         }
         if ($model->save()) {
             if (isset($model->image)) {
                 $model->image->saveAs(Yii::app()->basePath . '/../images/recruitment/' . $model->image->name);
             }
             if (isset($docs)) {
                 mkdir(Yii::getPathOfAlias('webroot') . '/images/recruitment/' . $model->id);
                 //chmod(Yii::getPathOfAlias('webroot').'/images/recruitment/'.$model->id, 0755);
                 foreach ($docs as $image => $pic) {
                     $pic->saveAs(Yii::app()->basePath . '/../images/recruitment/' . $model->id . '/' . $pic->name);
                 }
             }
             $this->redirect(array('/m1/gRecruitment'));
         }
     }
     $this->render('create', array('model' => $model));
 }
开发者ID:rusli-nasir,项目名称:ERP_Accounting_Indonesia,代码行数:34,代码来源:GRecruitmentController.php

示例3: saves

 public static function saves($typeModel, $idModel, $files_field_name = 'upload', $need_file_name = '')
 {
     $Uploads = CUploadedFile::getInstancesByName($files_field_name);
     if (is_null($Uploads)) {
         return false;
     }
     $folder = self::makePath($typeModel, $idModel);
     if (!file_exists($folder)) {
         mkdir($folder, 0777, true);
     }
     $arNames = array();
     foreach ($Uploads as $Upload) {
         if ($need_file_name == '') {
             $newName = str_replace('.' . $Upload->getExtensionName(), '', urlencode($Upload->getName())) . "-" . date("YmdHis", time()) . '.' . $Upload->getExtensionName();
         } else {
             //добавка для сохранения кадров под конкретным именем
             $newName = $need_file_name;
         }
         $newPath = $folder . self::DS . $newName;
         if ($Upload->saveAs($newPath)) {
             if (file_exists($newPath)) {
                 $arNames[] = $newName;
             } else {
                 return false;
             }
         } else {
             return false;
         }
     }
     return $arNames;
 }
开发者ID:dmitryplus,项目名称:gb,代码行数:31,代码来源:UploadFile.php

示例4: actionEdit

 /**
  * edit a particular model.
  */
 public function actionEdit()
 {
     $this->layout = '//layouts/notitle_main';
     $infoType = $this->getInfoType();
     $basicModelName = ucfirst(strtolower($infoType)) . 'InfoView';
     $isPageDirty = 0;
     $actionType = 'view';
     if (!empty($_GET['action'])) {
         $actionType = $_GET['action'];
     }
     list($productId, $model, $customInfo, $customFieldArr) = InfoService::initInfoPage($infoType, $this, $actionType, Yii::app()->request);
     if (!Info::isProductAccessable($productId)) {
         throw new CHttpException(400, Yii::t('Common', 'Required URL not found or permission denied.'));
     }
     if (isset($_POST[$basicModelName])) {
         if ('' == $_POST['templateTitle'] && empty($_POST['isPageDirty']) && !empty($model->id) && $this->isEditAction($actionType)) {
             $this->redirect(array('edit', 'type' => $infoType, 'id' => $model->id));
         } else {
             $attachmentFile = CUploadedFile::getInstancesByName('attachment_file');
             list($model, $customFieldArr) = InfoService::saveInfoPage($infoType, $model, $customInfo, $attachmentFile, $this, $actionType, Yii::app()->request);
             $isPageDirty = 1;
         }
     }
     $buttonList = InfoService::getButtonList($infoType, $actionType, $model);
     $this->render('edit', array('infoType' => $infoType, 'isPageDirty' => $isPageDirty, 'actionType' => $actionType, 'model' => $model, 'buttonList' => $buttonList, 'customfield' => $customFieldArr));
 }
开发者ID:mjrao,项目名称:BugFree,代码行数:29,代码来源:InfoController.php

示例5: actionContact

 /**
  * Displays the contact page
  */
 public function actionContact()
 {
     $model = new ContactForm();
     if (isset($_POST['ContactForm'])) {
         $model->attributes = $_POST['ContactForm'];
         if ($model->validate()) {
             //$attachment = Yii::app()->baseUrl.'/images/ban_admin.JPG';
             $images = CUploadedFile::getInstancesByName('images');
             $attachement = Yii::getPathOfAlias('webroot.files') . $model->file;
             $mail = Yii::app()->Smtpmail;
             $mail->SetFrom('admin@cads.mys', $model->name);
             $mail->Subject = $model->subject;
             $msg = $model->body . '<br />' . $model->email . '<br/>' . $model->name;
             $mail->MsgHTML($msg);
             $mail->CharSet = "UTF-8";
             $mail->AddAddress('zmahazhir@gmail.com', "CADS Programmer");
             $mail->AddAddress($model->email, "CADS Programmer");
             $mail->AddAttachment($attachement);
             if (!$mail->Send()) {
                 Yii::app()->user->setFlash('error', 'Error while sending email: ' . $mail->getError());
             }
             Yii::app()->user->setFlash('contact', 'You Email have been Sent');
             $this->refresh();
         }
     }
     $this->render('contact', array('model' => $model));
 }
开发者ID:TheTypoMaster,项目名称:myapps,代码行数:30,代码来源:SiteController.php

示例6: actionUpdate

 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Post'])) {
         $_POST['Post']['images'] = $model->images;
         $_POST['Post']['author_id'] = $model->author_id;
         $model->attributes = $_POST['Post'];
         $images = CUploadedFile::getInstancesByName('images');
         if (isset($images) && count($images) > 0) {
             $pic_names = array();
             foreach ($images as $image => $pic) {
                 $sourcePath = pathinfo($pic->getName());
                 $pic_name = time() . '-' . ++$image . '-' . $model->author_id . '.' . $sourcePath['extension'];
                 $path = Yii::getPathOfAlias('webroot') . "/images/";
                 if ($pic->saveAs($path . $pic_name)) {
                     $pic_names[] = $pic_name;
                 }
             }
             $model->images = implode(",", $pic_names);
         }
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('update', array('model' => $model));
 }
开发者ID:OlegYakovlev1,项目名称:yiitest,代码行数:33,代码来源:PostController.php

示例7: actionIndex

 public function actionIndex($is_product = 1)
 {
     if (!empty($_POST)) {
         $is_new_product = $is_product;
         $images = CUploadedFile::getInstancesByName('images');
         if (isset($images) && count($images) > 0) {
             // go through each uploaded image
             foreach ($images as $image => $pic) {
                 $model = new Slides();
                 $imageType = explode('.', $pic->name);
                 $imageType = $imageType[count($imageType) - 1];
                 $imageName = md5(uniqid()) . '.' . $imageType;
                 if ($pic->saveAs(Yii::getPathOfAlias('webroot') . '/upload/images/' . $imageName)) {
                     $model->image = $imageName;
                     $model->name = $pic->name;
                     $model->is_product = $is_new_product;
                     $model->save();
                     Yii::app()->user->setFlash('success', translate('Thêm thành công.'));
                 }
                 // handle the errors here, if you want
             }
         }
         PIUrl::createUrl('/admin/slides/index', array('is_product' => $is_product));
     }
     $criteria = new CDbCriteria();
     $criteria->addCondition("is_product= {$is_product}");
     $criteria->order = 'id DESC';
     $count = Slides::model()->count($criteria);
     $pages = new CPagination($count);
     // results per page
     $pages->pageSize = 6;
     $pages->applyLimit($criteria);
     $model = Slides::model()->findAll($criteria);
     $this->render('index', compact('model', 'pages'));
 }
开发者ID:phiphi1992,项目名称:alongaydep,代码行数:35,代码来源:SlidesController.php

示例8: actionUpload

 /**
  * Action which handles file uploads
  *
  * The result is an json array of all uploaded files.
  */
 public function actionUpload()
 {
     $files = array();
     foreach (CUploadedFile::getInstancesByName('files') as $cFile) {
         $files[] = $this->handleFileUpload($cFile);
     }
     return $this->renderJson(array('files' => $files));
 }
开发者ID:ahdail,项目名称:humhub,代码行数:13,代码来源:FileController.php

示例9: getuppload_files

 public function getuppload_files()
 {
     if (!$this->isimport) {
         return CUploadedFile::getInstancesByName('');
     } else {
         return array(123, 321);
     }
 }
开发者ID:nikel303,项目名称:RosYama.2,代码行数:8,代码来源:HoleAnswers.php

示例10: updateProductImages

 public function updateProductImages(Product $product)
 {
     foreach (CUploadedFile::getInstancesByName('ProductImage') as $key => $image) {
         $productImage = new ProductImage();
         $productImage->product_id = $product->id;
         $productImage->attributes = $_POST['ProductImage'][$key];
         $productImage->addFileInstanceName('ProductImage[' . $key . '][name]');
         $productImage->save();
     }
 }
开发者ID:RonLab1987,项目名称:43berega,代码行数:10,代码来源:ProductBackendController.php

示例11: testGetInstancesByNamePartOfOtherName

 /**
  * @depends testGetInstancesByName
  *
  * @see https://github.com/yiisoft/yii/issues/159
  */
 public function testGetInstancesByNamePartOfOtherName()
 {
     $baseInputName = 'base_name';
     $tailedInputName = $baseInputName . '_tail';
     $_FILES[$baseInputName] = array('name' => $baseInputName . '.dat', 'type' => 'somemime/' . $baseInputName, 'tmp_name' => '/tmp/' . $baseInputName, 'error' => UPLOAD_ERR_OK, 'size' => 100);
     $_FILES[$tailedInputName] = array('name' => $tailedInputName . '.dat', 'type' => 'somemime/' . $tailedInputName, 'tmp_name' => '/tmp/' . $tailedInputName, 'error' => UPLOAD_ERR_OK, 'size' => 100);
     $uploadedFiles = CUploadedFile::getInstancesByName($baseInputName);
     foreach ($uploadedFiles as $uploadedFile) {
         $this->assertEquals($_FILES[$baseInputName]['name'], $uploadedFile->getName(), 'Wrong file fetched!');
     }
 }
开发者ID:super-d2,项目名称:codeigniter_demo,代码行数:16,代码来源:CUploadedFileTest.php

示例12: actionUpload

 public function actionUpload($recordType, $id, $InstanceName, $fileType = "File", $filePath = "", $fileExtName = "", $newResizeWidth = 1600, $newResizeHeight = 1280)
 {
     if (isset($recordType) && isset($id)) {
         $uploadedFiles = CUploadedFile::getInstancesByName($InstanceName);
         $modelName = $fileType;
         if (empty($filePath)) {
             $fileParam = $fileType == 'File' ? 'filePath' : 'imgPath';
             $filePath = Yii::app()->params[$fileParam] . '/' . $recordType . '/' . $id . '/';
         }
         Yii::app()->file->set($filePath)->createDir(0777);
         $uploadedFilesIds = array();
         if ($uploadedFiles) {
             foreach ($uploadedFiles as $fileKey => $fileVal) {
                 $fileName = str_replace(array(" ", "-"), "_", $fileVal->name);
                 list($baseName, $ext) = explode(".", $fileName);
                 $fileName = $baseName . "_" . $fileExtName . "." . $ext;
                 list($thisWidth, $thisHeight, $type, $attr) = getimagesize($fileVal->tempName);
                 $imageTool = Yii::app()->imagemod->load($fileVal->tempName);
                 if ($thisHeight > $thisWidth) {
                     //verticle image
                     if ($thisHeight > $newResizeHeight) {
                         $imageTool->image_resize = true;
                         $imageTool->image_ratio_x = true;
                         $imageTool->image_y = $newResizeHeight;
                     }
                 } else {
                     //horizontal image
                     if ($thisWidth > $newResizeWidth) {
                         $imageTool->image_resize = true;
                         $imageTool->image_ratio_y = true;
                         $imageTool->image_x = $newResizeWidth;
                     }
                 }
                 $imageTool->file_new_name_body = $baseName . "_" . $fileExtName;
                 $imageTool->file_new_name_ext = $ext;
                 $imageTool->process($filePath);
                 if ($imageTool->processed) {
                     $file = new $modelName();
                     $file->recordId = $id;
                     $file->recordType = $recordType;
                     $file->realName = $fileVal->name;
                     $file->name = $fileName;
                     $file->mimeType = $fileVal->type;
                     $file->fullPath = realpath($filePath);
                     $file->save(false);
                     $uploadedFilesIds[$file->id] = $file->id;
                 }
             }
         }
         return $uploadedFilesIds;
     } else {
         return false;
     }
 }
开发者ID:jankichaudhari,项目名称:yii-site,代码行数:54,代码来源:FileController.php

示例13: actionImport

 public function actionImport()
 {
     $model = new Maestrocompo();
     $model->setScenario("cargamasiva");
     if (isset($_POST['Maestrocompo'])) {
         echo " Si salio el POST                             OK ->   ";
         $model->attributes = $_POST['Maestrocompo'];
         $filelist = CUploadedFile::getInstancesByName('csvfile');
         // if($filelist)
         // $model->csvfile=1;
         //if($model->validate())
         // {
         // echo " Se valido  ....";
         foreach ($filelist as $file) {
             try {
                 $transaction = Yii::app()->db->beginTransaction();
                 $handle = fopen("{$file->tempName}", "r");
                 echo "el handle  es ...." . gettype($handle);
                 $row = 2;
                 ini_set('max_execution_time', '120');
                 while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
                     if ($row > 1) {
                         $newmodel = new Maestrocompo();
                         $newmodel->codigo = $data[0];
                         $newmodel->um = $data[1];
                         $newmodel->codtipo = $data[2];
                         $newmodel->descripcion = $data[3];
                         $newmodel->marca = $data[4];
                         $newmodel->marca = $data[5];
                         $newmodel->marca = $data[6];
                         //$newmodel->setScenario("cargamasiva");
                         /*$newmodel->cantlibre=$data[1];
                         		echo " el id  a cargar es :  ".$data[0]."   \n";*/
                         if ($newmodel->save()) {
                             //echo " grabo  carajo --------------------> :  ".$data[1]."   \n";
                             echo "ok  " . $newmodel->codigo . "\n";
                         } else {
                             //echo " NO grabo  xxxxxxxxxxx-> :  ".$data[1]."   \n";
                         }
                     }
                     $row++;
                 }
                 $transaction->commit();
             } catch (Exception $error) {
                 print_r($error);
                 $transaction->rollback();
             }
             yii::app()->end();
         }
     } else {
         echo "NO se ha enviado ningun form";
     }
     $this->render('cargamaestro', array('model' => $model));
 }
开发者ID:hipogea,项目名称:nautilus,代码行数:54,代码来源:MaestrocompoController.php

示例14: saveImages

 /**
  * What the hell is this method? it was discussed over 9000 times that such code
  * should not be anywhere close to controller as it is pure model's logic.
  *
  * @param $model
  * @param $instanceName
  * @param $recordType
  * @return array
  */
 private function saveImages($model, $instanceName, $recordType)
 {
     /** @var $images CUploadedFile[] */
     $images = CUploadedFile::getInstancesByName($instanceName);
     $imagePath = $this->pathToImages . "/" . $model->id;
     $newResizeWidth = 1920;
     $newResizeHeight = 1024;
     Yii::app()->file->set($imagePath)->createDir(0777);
     $ids = array();
     if ($images) {
         if (File::model()->findByAttributes(['recordId' => $model->id, 'recordType' => $recordType])) {
             File::model()->findByAttributes(['recordId' => $model->id, 'recordType' => $recordType])->delete();
         }
         foreach ($images as $num => $pic) {
             $imageNameAr = explode(".", $pic->name);
             $fileName = $recordType;
             $ext = end($imageNameAr);
             $imageName = $fileName . '.' . $ext;
             list($thisWidth, $thisHeight, $type, $attr) = getimagesize($pic->tempName);
             $imageTool = Yii::app()->imagemod->load($pic->tempName);
             if ($thisHeight > $thisWidth) {
                 //verticle image
                 if ($thisHeight > $newResizeHeight) {
                     $imageTool->image_resize = true;
                     $imageTool->image_ratio_x = true;
                     $imageTool->image_y = $newResizeHeight;
                 }
             } else {
                 //horizontal image
                 if ($thisWidth > $newResizeWidth) {
                     $imageTool->image_resize = true;
                     $imageTool->image_ratio_y = true;
                     $imageTool->image_x = $newResizeWidth;
                 }
             }
             $imageTool->file_new_name_body = $fileName;
             $imageTool->file_new_name_ext = $ext;
             $imageTool->process($imagePath);
             if ($imageTool->processed) {
                 $img = new File();
                 $img->recordId = $model->id;
                 $img->recordType = $recordType;
                 $img->realName = $pic->name;
                 $img->name = $imageName;
                 $img->mimeType = $pic->type;
                 $img->fullPath = realpath($imagePath);
                 $img->save(false);
                 $ids[$img->id] = $img->id;
             }
         }
     }
     return $ids;
 }
开发者ID:jankichaudhari,项目名称:yii-site,代码行数:62,代码来源:PropertyCategoryController.php

示例15: getInstancesByName

 /**
  * Returns an array of instances starting with specified array name.
  *
  * If multiple files were uploaded and saved as 'Files[0]', 'Files[1]', 'Files[n]'..., you can have them all by
  * passing 'Files' as array name.
  *
  * @param string $name                  The name of the array of files
  * @param bool   $lookForSingleInstance If set to true, will look for a single instance of the given name.
  *
  * @return UploadedFile[] The array of UploadedFile objects. Empty array is returned if no adequate upload was
  *                        found. Please note that this array will contain all files from all subarrays regardless
  *                        how deeply nested they are.
  */
 public static function getInstancesByName($name, $lookForSingleInstance = true)
 {
     $name = static::_normalizeName($name);
     $instances = parent::getInstancesByName($name);
     if (!$instances && $lookForSingleInstance) {
         $singleInstance = parent::getInstanceByName($name);
         if ($singleInstance) {
             $instances[] = $singleInstance;
         }
     }
     return $instances;
 }
开发者ID:paulcarvill,项目名称:Convergence-craft,代码行数:25,代码来源:UploadedFile.php


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