• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP CUploadedFile类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: save

 /**
  * @param \CActiveRecord $model
  * @param string $attribute имя поля, содержащего CUploadedFile. В последствии этому полю будет присвоено имя файла изображения.
  * @param \CUploadedFile $image
  * @param array $sizes
  *
  * @throws \CException
  *
  * @return bool
  */
 public function save(\CActiveRecord $model, $attribute = 'image', \CUploadedFile $image, $sizes = [])
 {
     $folderModel = $this->extractPath($model, $attribute, true);
     if (!file_exists($folderModel)) {
         mkdir($folderModel);
     }
     $imageExtension = isset($this->mimeToExtension[$image->getType()]) ? $this->mimeToExtension[$image->getType()] : 'jpg';
     $imageId = $this->getRandomHash($model, $attribute);
     $imagePathTemp = \Yii::getPathOfAlias('temp') . '/' . $imageId . '.' . $imageExtension;
     if ($image->saveAs($imagePathTemp)) {
         foreach ($sizes as $sizeName => $size) {
             $folderModelAttribute = $this->extractPath($model, $attribute);
             if (!file_exists($folderModelAttribute)) {
                 mkdir($folderModelAttribute);
             }
             $quality = array_key_exists('quality', $size) ? intval($size['quality']) : self::DEFAULT_QUALITY;
             if ($quality <= 0 or $quality > 100) {
                 $quality = self::DEFAULT_QUALITY;
             }
             $pathImageSize = $folderModelAttribute . '/' . $imageId . '_' . $sizeName . '.' . $imageExtension;
             if (array_key_exists('enabled', $size) and $size['enabled'] == false) {
                 if (array_key_exists('resave', $size) and $size['resave'] == false) {
                     rename($imagePathTemp, $pathImageSize);
                 } else {
                     $this->processor->open($imagePathTemp)->save($pathImageSize, ['quality' => $quality]);
                 }
             } else {
                 $this->processor->open($imagePathTemp)->thumbnail(new Box($size['width'], $size['height']), (!isset($size['inset']) or $size['inset']) ? ImageInterface::THUMBNAIL_INSET : ImageInterface::THUMBNAIL_OUTBOUND)->save($pathImageSize, ['quality' => $quality]);
             }
         }
     } else {
         throw new \CException('can not save image');
     }
     return [self::KEY_ID => $imageId, self::KEY_EXT => $imageExtension];
 }
开发者ID:happyproff,项目名称:yii-easyimages,代码行数:45,代码来源:EasyImages.php


示例2: saveMetaDataForUploadedFile

 /**
  * Save file meta data to persistent storage and return id.
  *
  * @param \CUploadedFile $uploadedFile uploaded file.
  *
  * @return integer meta data identifier in persistent storage.
  */
 public function saveMetaDataForUploadedFile(\CUploadedFile $uploadedFile)
 {
     $ext = \mb_strtolower($uploadedFile->getExtensionName(), 'UTF-8');
     $realName = pathinfo($uploadedFile->getName(), PATHINFO_FILENAME);
     FPM::m()->getDb()->createCommand()->insert(FPM::m()->tableName, array('extension' => $ext, 'real_name' => $realName));
     return FPM::m()->getDb()->getLastInsertID();
 }
开发者ID:metalguardian,项目名称:yii-file-processor,代码行数:14,代码来源:FileTransfer.php


示例3: run

 public function run()
 {
     $this->prepare();
     if ($file = new CUploadedFile($this->md5($_FILES['file']['name']), $_FILES['file']['tmp_name'], $_FILES['file']['type'], $_FILES['file']['size'], $_FILES['file']['error'])) {
         if ($file->saveAs($this->basePath . $file->getName())) {
             $this->append($file->getName());
         }
     }
 }
开发者ID:hipogea,项目名称:zega,代码行数:9,代码来源:UploadAction.php


示例4: changeLogo

 public function changeLogo(CUploadedFile $uploadedFile)
 {
     $basePath = Yii::app()->getModule('cabinet')->getUploadPath();
     //создаем каталог для аватарок, если не существует
     if (!is_dir($basePath) && !@mkdir($basePath, 0755, true)) {
         throw new CException(Yii::t('default', 'It is not possible to create directory for logos!'));
     }
     $filename = $this->id . '_' . time() . '.' . $uploadedFile->extensionName;
     // обновить файл
     //$this->removeOldLogo();
     if (!$uploadedFile->saveAs($basePath . $filename)) {
         throw new CException(Yii::t('default', 'It is not possible to save logos!'));
     }
     // получить запись лого
     $photo = $this->with('photo')->find('photo.id=:id', [':id' => $this->logo_id]);
     $webroot = Yii::getpathOfAlias('webroot');
     $trimPath = str_replace($webroot, '', $basePath);
     $logoFileOld = null;
     $File = new File();
     $File->model = 'Company';
     $File->type = 'image';
     $File->size = filesize($basePath . $filename);
     $File->name = $filename;
     $File->path = $trimPath . $filename;
     $File->record_id = 0;
     if (!is_null($photo['photo'])) {
         $File->id = $photo['photo']['id'];
         $File->isNewRecord = false;
         $logoFileOld = $photo['photo']['path'];
     }
     if ($File->save()) {
         if (0 != strcmp($logoFileOld, $File->path)) {
             @unlink($webroot . $logoFileOld);
         }
     } else {
         yii::log("changeLogo save FAILED id=[" . $File->id . "]", "info");
     }
     if ($this->logo_id != $File->id) {
         // поменять logo_id
         $this->logo_id = $File->id;
         if ($this->validate(['logo_id'])) {
             if (true === $this->update(['logo_id'])) {
             } else {
                 Yii::log("changeLogo update logo_id FAILED", 'info');
             }
         } else {
             Yii::log("changeLogo validate logo_id FAILED", 'info');
         }
     }
     //$this->logo = $filename;
     return true;
 }
开发者ID:alexanderkuz,项目名称:test-yii2,代码行数:52,代码来源:Company.php


示例5: actionEdit

 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  */
 public function actionEdit()
 {
     $model = $this->loadUser();
     $profile = $model->profile;
     // ajax validator
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'profile-form') {
         echo UActiveForm::validate(array($model, $profile));
         Yii::app()->end();
     }
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         $model->image = CUploadedFile::getInstance($model, 'image');
         $profile->attributes = $_POST['Profile'];
         if ($model->validate() && $profile->validate()) {
             $model->save();
             $profile->save();
             Yii::app()->user->updateSession();
             Yii::app()->user->setFlash('profileMessage', Yii::t('main', "Data saved successfully!"));
             $this->redirect(array('/user/profile'));
         } else {
             $profile->validate();
         }
     }
     $this->render('edit', array('model' => $model, 'profile' => $profile));
 }
开发者ID:blrtromax,项目名称:seobility,代码行数:29,代码来源:ProfileController.php


示例6: 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


示例7: afterValidate

 public function afterValidate($event)
 {
     $this->prepareDataDirectory();
     $file = CUploadedFile::getInstanceByName($this->uploadInstance);
     if ($file instanceof CUploadedFile && $file->getError() == UPLOAD_ERR_OK && !$this->Owner->hasErrors()) {
         $uniqueFilename = P3StringHelper::generateUniqueFilename($file->getName());
         $fullFilePath = $this->_fullDataPath . DIRECTORY_SEPARATOR . $uniqueFilename;
         $relativeFilePath = $this->_relativeDataPath . DIRECTORY_SEPARATOR . $uniqueFilename;
         if ($file->saveAs($fullFilePath)) {
             #echo $fullFilePath;exit;
             if (!$this->Owner->isNewRecord) {
                 $this->deleteFile($this->Owner->path);
             }
             if (!$this->Owner->title) {
                 $this->Owner->title = P3StringHelper::cleanName($file->name, 32);
             }
             $this->Owner->path = $relativeFilePath;
             $this->Owner->mimeType = $file->type;
             $this->Owner->size = $file->size;
             $this->Owner->originalName = $file->name;
             $this->Owner->md5 = md5_file($fullFilePath);
         } else {
             $this->Owner->addError('filePath', 'File uploaded failed!');
         }
     } else {
         if ($this->Owner->isNewRecord) {
             #$this->Owner->addError('filePath', 'No file uploaded!');
             Yii::trace('No file uploaded!');
         }
     }
 }
开发者ID:ranvirp,项目名称:rdp,代码行数:31,代码来源:P3FileUploadBehavior.php


示例8: actionUpload

 /**
  * Upload file and process it for mapping.
  */
 public function actionUpload()
 {
     // Get import post
     $import = craft()->request->getRequiredPost('import');
     // Get file
     $file = \CUploadedFile::getInstanceByName('file');
     // Is file valid?
     if (!is_null($file)) {
         // Determine folder
         $folder = craft()->path->getStoragePath() . 'import/';
         // Ensure folder exists
         IOHelper::ensureFolderExists($folder);
         // Get filepath - save in storage folder
         $path = $folder . $file->getName();
         // Save file to Craft's temp folder for later use
         $file->saveAs($path);
         // Put vars in model
         $model = new ImportModel();
         $model->filetype = $file->getType();
         // Validate filetype
         if ($model->validate()) {
             // Get columns
             $columns = craft()->import->columns($path);
             // Send variables to template and display
             $this->renderTemplate('import/_map', array('import' => $import, 'file' => $path, 'columns' => $columns));
         } else {
             // Not validated, show error
             craft()->userSession->setError(Craft::t('This filetype is not valid') . ': ' . $model->filetype);
         }
     } else {
         // No file uploaded
         craft()->userSession->setError(Craft::t('Please upload a file.'));
     }
 }
开发者ID:radarseven,项目名称:import,代码行数:37,代码来源:ImportController.php


示例9: 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['Scodobjventascaract'])) {
         $model->attributes = $_POST['Scodobjventascaract'];
         // Verificar si existe un archivo que actualizar en la creacion
         if (isset($_FILES) && $_FILES['Scodobjventascaract']['error']['imagen'] == 0) {
             // Obtenemos la instancia del documento
             $fDocumento = CUploadedFile::getInstance($model, 'imagen');
             $sPathDocumento = $sPathFile . '/' . $model->id_cod_obj_venta . '/';
             if (!file_exists($sPathDocumento)) {
                 mkdir($sPathDocumento, 0777, true);
             }
             $fDocumento->saveAs($sPathDocumento . $fDocumento->getName());
             $model->imagen = $fDocumento->getName();
             // $this->refresh();
         }
         if ($model->save()) {
             $this->redirect(array('scodobjventas/' . $model->id_cod_obj_venta));
         }
     }
     $this->render('update', array('model' => $model));
 }
开发者ID:bbustillos,项目名称:saleh_dev,代码行数:30,代码来源:ScodobjventascaractController.php


示例10: actionUpdate

 public function actionUpdate()
 {
     $model = $this->loadModel($id);
     if (isset($_POST['Avatars'])) {
         $model->attributes = $_POST['Avatars'];
         $model->icon = CUploadedFile::getInstance($model, 'icon');
         if ($model->icon) {
             $sourcePath = pathinfo($model->icon->getName());
             $fileName = date('m-d') . Yii::app()->user->name . '.' . $sourcePath['extension'];
             $model->image = $fileName;
         }
         if ($model->save()) {
             //Если отмечен чекбокс «удалить файл»
             if ($model->del_img) {
                 if (file_exists($_SERVER['DOCUMENT_ROOT'] . Yii::app()->urlManager->baseUrl . '/images/' . $model->image)) {
                     //удаляем файл
                     unlink('./images/' . $model->image);
                     $model->image = '';
                 }
             }
             //Если поле загрузки файла не было пустым, то
             if ($model->icon) {
                 $file = './images/' . $fileName;
                 $model->icon->saveAs($file);
                 $image = Yii::app()->image->load($file);
                 $image->resize(100, 100);
                 $image->save();
             }
             $this->redirect(array('update', 'id' => $model->id));
         }
     }
     $this->render('update', array('model' => $model));
 }
开发者ID:holyshved,项目名称:guestbook,代码行数:33,代码来源:AvatarsController.php


示例11: actionCreate

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new MCompany();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['MCompany'])) {
         $model->attributes = $_POST['MCompany'];
         $brandImage = CUploadedFile::getInstance($model, 'image_id');
         if ($brandImage instanceof CUploadedFile) {
             $image = new MImage();
             $path_parts = pathinfo($brandImage->getName());
             $file_name = time() . "." . $path_parts['extension'];
             $path = Yii::app()->storagePath . "brand" . DIRECTORY_SEPARATOR . $file_name;
             $brandImage->saveAs($path);
             $image->created = time();
             $image->path = "/storage/brand/" . $file_name;
             $image->created_by = Yii::app()->user->id;
             $image->save(false);
         }
         $model->image_id = $image->id;
         $model->created = time();
         $model->created_by = Yii::app()->user->id;
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
开发者ID:dhrutidas,项目名称:shantibar,代码行数:32,代码来源:CompanyController.php


示例12: 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'];
         $picture_name = '';
         $picture_file = CUploadedFile::getInstance($model, 'file');
         $model->file = $picture_file;
         if ($picture_file) {
             $picture_name = $picture_file->name;
             if (!is_dir(Yii::getPathOfAlias('webroot') . '/themes/gallery-images/')) {
                 mkdir(Yii::getPathOfAlias('webroot') . '/themes/gallery-images/');
             }
             if (!is_dir(Yii::getPathOfAlias('webroot') . '/themes/gallery-images/')) {
                 mkdir(Yii::getPathOfAlias('webroot') . '/themes/gallery-images/');
                 $picture_file->SaveAs(Yii::getPathOfAlias('webroot') . '/themes/gallery-images' . $picture_file->getName());
             } else {
                 $picture_file->SaveAs(Yii::getPathOfAlias('webroot') . '/themes/gallery-images' . $picture_file->getName());
             }
         }
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->photo_id));
         }
     }
     $this->render('create', array('model' => $model));
 }
开发者ID:JexIboy,项目名称:lis-pglu,代码行数:32,代码来源:PhotoController.php


示例13: run

 public function run()
 {
     $file = CUploadedFile::getInstanceByName('file');
     $path = $this->getUniquePath($this->filesDir(), $file->extensionName);
     $file->saveAs($path);
     echo CHtml::link($file->name, "http://" . $_SERVER["HTTP_HOST"] . '/' . $path);
 }
开发者ID:ashishverma025,项目名称:yii2,代码行数:7,代码来源:FileUploadAction.php


示例14: 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['Partner'])) {
         $model->attributes = $_POST['Partner'];
         $model->fileLogo = CUploadedFile::getInstance($model, 'fileLogo');
         if ($model->fileLogo) {
             if ($model->validate(array('fileLogo'))) {
                 $fileName = $this->getAndSaveUploadedFile($model);
                 if ($fileName) {
                     if ($model->logo_path && file_exists($model->logo_path)) {
                         unlink($model->logo_path);
                     }
                     $model->logo_path = $fileName;
                 }
             }
         }
         if ($model->save()) {
             $this->redirect(array('admin'));
         }
     }
     $this->render('update', array('model' => $model));
 }
开发者ID:laiello,项目名称:flexiblearning,代码行数:30,代码来源:PartnerController.php


示例15: 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['Slider'])) {
         if (file_exists(Yii::app()->basePath . self::URLUPLOAD . $model->file_name)) {
             unlink(Yii::app()->basePath . self::URLUPLOAD . $model->file_name);
         }
         $model->attributes = $_POST['Slider'];
         $uploadedFile = CUploadedFile::getInstance($model, 'file_name');
         $rnd = rand(0, 999999);
         $wkt = date('m-d-Y-h-i-s', time());
         $fileName = "{$wkt}_{$rnd}_{$uploadedFile}";
         $model->file_name = $fileName;
         $model->last_update = new CDbExpression('NOW()');
         if ($model->save()) {
             if ($uploadedFile !== null) {
                 $uploadedFile->saveAs(Yii::app()->basePath . self::URLUPLOAD . $model->file_name);
             }
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('update', array('model' => $model));
 }
开发者ID:hendri30,项目名称:TechnorollWeb,代码行数:30,代码来源:SliderController.php


示例16: 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);
     $menu = $model->attributes;
     if (isset($_POST['FrontMenu'])) {
         $model->attributes = $_POST['FrontMenu'];
         foreach ($this->uploadArr as $column) {
             $file = CUploadedFile::getInstance($model, $column);
             //获取表单名为filename的上传信息
             if ($file) {
                 $model->{$column} = $this->uploadIcon($file);
                 if ($menu[$column]) {
                     $ftp = new Ftp();
                     $res = $ftp->delete_file('common/frontmenu/' . $menu[$column]);
                     $ftp->close();
                 }
             } else {
                 unset($model->{$column});
             }
         }
         if (!$model->ParentID) {
             $model->ParentID = 0;
         }
         if ($model->save()) {
             $this->freshMenuCache();
             $this->redirect(array('admin'));
         }
     }
     $this->render('update', array('model' => $model));
 }
开发者ID:zwq,项目名称:unpei,代码行数:35,代码来源:FrontmenuController.php


示例17: actionCreate

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Pic();
     if (isset($_POST['Pic'])) {
         $image = CUploadedFile::getInstances($model, 'big_pic');
         $is_fail = true;
         foreach ($image as $img) {
             $model->created_time = date("Y-m-d H:i:s");
             $microtime = microtime(true);
             $model->big_pic = './images/pic/' . $microtime . '.' . $img->extensionName;
             $mini_path = $this->create_mini_pic($img->tempName, $microtime);
             $model->mini_pic = $mini_path;
             if ($model->save()) {
                 $is_fail = false;
                 $img->saveAs($model->big_pic);
             } else {
                 print_r($model->getErrors());
             }
         }
         if (!$is_fail) {
             $this->redirect(array('index'));
         }
     }
     $this->render('create', array('model' => $model));
 }
开发者ID:renlong567,项目名称:YiiYurenGithub,代码行数:29,代码来源:PicController.php


示例18: actionUpload

 public function actionUpload()
 {
     $cs = Yii::app()->getClientScript();
     $cs->registerCoreScript('jquery');
     $model = new Image();
     if (isset($_FILES['Image'])) {
         $model->image = CUploadedFile::getInstance($model, 'image');
         if ($model->validate()) {
             $name = $model->image->name;
             if (file_exists(Yii::app()->params['imageHomeAbs'] . $name)) {
                 // already there
                 $v = 2;
                 preg_match('/(\\w+)\\.(\\w+)/', $name, $match);
                 do {
                     $name = $match[1] . '(' . $v++ . ').' . $match[2];
                 } while (file_exists(Yii::app()->params['imageHomeAbs'] . $name));
             }
             if ($model->validate()) {
                 $model->image->saveAs(Yii::app()->params['imageHomeAbs'] . $name);
             }
         }
     }
     // directory search
     $current = Yii::app()->params['imageHomeAbs'];
     $filelist = array();
     $d = dir($current);
     while ($tmp = $d->read()) {
         if ($tmp != '.' && $tmp != '..' && $tmp != '.svn') {
             array_push($filelist, $tmp);
         }
     }
     asort($filelist, SORT_STRING);
     $this->render('gallery', array('model' => $model, 'filelist' => $filelist, 'current' => $current, 'cs' => $cs));
 }
开发者ID:GowthamThangamani,项目名称:yii-blogdemo-enhanced,代码行数:34,代码来源:ImageController.php


示例19: beforeSave

 public function beforeSave()
 {
     parent::beforeSave();
     $picture = CUploadedFile::getInstance($this, 'image');
     if ($picture) {
         $imagename = $picture->getTempName();
         $image = Yii::app()->image->load($imagename);
         if ($image) {
             if ($this->avatar) {
                 unlink($_SERVER['DOCUMENT_ROOT'] . $this->avatar_folder . '/' . $this->avatar);
             }
             if ($image->width >= $image->height) {
                 $image->resize(20000, 93)->rotate(0)->quality(90)->sharpen(20);
             } else {
                 $image->resize(93, 20000)->rotate(0)->quality(90)->sharpen(20);
             }
             $image->crop(93, 93);
             $file_name = rand() . '.' . $picture->extensionName;
             $savename = $_SERVER['DOCUMENT_ROOT'] . $this->avatar_folder . '/' . $file_name;
             $image->save($savename);
             $this->avatar = $file_name;
         }
     }
     return true;
 }
开发者ID:snipesn,项目名称:UkrYama-2,代码行数:25,代码来源:Profile.php


示例20: actionUpdate

 public function actionUpdate($id = null)
 {
     $model = Documents::model()->findByPk($id);
     $flag = 0;
     if (!empty($_POST['Documents'])) {
         $filename_old = $model->attributes['filename'];
         if (!empty(CUploadedFile::getInstance($model, 'filename')->name)) {
             $model->attributes = $_POST['Documents'];
             $model->filename = CUploadedFile::getInstance($model, 'filename');
             $filename = $model->filename;
             $document = explode('.', $model->filename->name);
             $filenameType = $document[count($document) - 1];
             $filenameName = md5(uniqid()) . '.' . $filenameType;
             $model->type = end($document);
             $model->size = $model->filename->size;
             $model->md5name = $filenameName;
             $model->filename = $document[count($document) - 2] . "." . $model->type;
             $filenames_path = Yii::getPathOfAlias('webroot') . '/upload/documents/' . $filenameName;
             $flag = 1;
         } else {
             $model->attributes = $_POST['Documents'];
             $model->filename = $filename_old;
         }
         $model->updated = time();
         if ($model->save()) {
             Yii::app()->user->setFlash('success', translate('Cập nhật thành công.'));
             if ($flag == 1) {
                 $filename->saveAs($filenames_path);
             }
             $this->redirect(PIUrl::createUrl('/admin/Documents/'));
         }
     }
     $dataCategories = categoriesDocuments::model()->getCategoriesDocument();
     $this->render('update', array('model' => $model, 'dataCategory' => $dataCategories));
 }
开发者ID:phiphi1992,项目名称:alongaydep,代码行数:35,代码来源:DocumentsController.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP CUrl类代码示例发布时间:2022-05-20
下一篇:
PHP CTitleBlock类代码示例发布时间:2022-05-20
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap