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


PHP CUploadedFile::getName方法代码示例

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


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

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

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

 /**
  * 
  * @param CUploadedFile $fileInstance
  */
 public function addFile($fileInstance, $filename = false, $extraFormat = false)
 {
     $filePath = $this->pathToData . DIRECTORY_SEPARATOR . $this->prefix . $this->id . DIRECTORY_SEPARATOR;
     $accessModel = new PropertyfileModel();
     $generateName = 'u' . md5(uniqid(""));
     $fullNameParts = explode('.', $fileInstance->getName());
     if (!$extraFormat) {
         $format = array_pop($fullNameParts);
     } else {
         $format = $extraFormat;
     }
     if (!$filename) {
         $filename = $generateName;
     } else {
         $filename = str_replace(' ', '', $filename);
     }
     $generateName .= $generateName . '.' . $format;
     $folder = YII::getPathOfAlias('application.data.id' . $this->id) . DIRECTORY_SEPARATOR;
     if (!is_dir($folder)) {
         return false;
     }
     $accessModel->unsetAttributes();
     $accessModel->setAttributes(array('property_id' => $this->id, 'filename' => $filename . '.' . $format, 'systempath' => $generateName));
     if (!$accessModel->save()) {
         return false;
     }
     if (!$fileInstance->saveAs($folder . $generateName, false)) {
         var_dump($filename . '.' . $format);
         v($folder . $generateName);
         return false;
     }
     $resultData = array('filename' => $filename, 'systemname' => $generateName, 'id' => $accessModel->getAttribute('id'));
     return $resultData;
 }
开发者ID:salem-dev-acc,项目名称:yiiapp,代码行数:38,代码来源:propertyFile.php

示例4: isAllowedType

 /**
  * @param CUploadedFile $image
  * @return bool
  */
 public static function isAllowedType(CUploadedFile $image)
 {
     $type = CFileHelper::getMimeType($image->getTempName());
     if (!$type) {
         $type = CFileHelper::getMimeTypeByExtension($image->getName());
     }
     return in_array($type, EventsImagesConfig::get('types'));
 }
开发者ID:bahdall,项目名称:karbella_event,代码行数:12,代码来源:EventsUploadedImage.php

示例5: isAllowedType

 /**
  * @param CUploadedFile $image
  * @return bool
  */
 public static function isAllowedType(CUploadedFile $image)
 {
     $type = CFileHelper::getMimeType($image->getTempName());
     if (!$type) {
         $type = CFileHelper::getMimeTypeByExtension($image->getName());
     }
     return in_array($type, array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png'));
 }
开发者ID:buildshop,项目名称:bs-common,代码行数:12,代码来源:ShopUploadedImage.php

示例6: isAllowedType

 /**
  * @param CUploadedFile $image
  * @return bool
  */
 public static function isAllowedType(CUploadedFile $image)
 {
     $type = CFileHelper::getMimeType($image->getTempName());
     if (!$type) {
         $type = CFileHelper::getMimeTypeByExtension($image->getName());
     }
     //return in_array($type, Yii::app()->params['storeImages']['types']);
     return in_array($type, StoreImagesConfig::get('types'));
 }
开发者ID:Aplay,项目名称:myhistorypark_site,代码行数:13,代码来源:FileImageValidator.php

示例7: store

 /**
  * Store Upload file to S3.
  * @param CUploadedFile $uploadedFile
  * @param string $bucket The file to create the object
  * @return string url to the file.
  */
 public function store($uploadedFile, $bucket = NULL)
 {
     if ($this->config['randomPath']) {
         $filePath = $this->config['pathPrefix'] . md5(date('His')) . '/' . $uploadedFile->getName();
     } else {
         $filePath = $this->config['pathPrefix'] . $uploadedFile->getName();
     }
     if ($bucket === NULL) {
         $bucket = $this->config['defaultBucket'];
     }
     /** @var CFResponse $result */
     $result = $this->s3->create_object($bucket, $filePath, array('fileUpload' => $uploadedFile->getTempName(), 'acl' => $this->config['defaultACL']));
     if ($result->isOk()) {
         return urldecode($this->s3->get_object_url($bucket, $filePath));
     } else {
         Yii::log("STATUS:" . $result->status . "\nHEDAER:" . $result->header . "\nBODY:" . $result->body, CLogger::LEVEL_ERROR, "application");
         throw new CException($result->status);
     }
 }
开发者ID:jamesmoey,项目名称:yii-amazon,代码行数:25,代码来源:AmazonS3Component.php

示例8: beforeSave

 protected function beforeSave()
 {
     if (parent::beforeSave()) {
         if ($this->getIsNewRecord()) {
             $this->status = self::STATUS_WAIT;
             $this->createdAt = date('Y-m-d H:i:s');
             $basePath = Yii::getPathOfAlias('application.runtime') . '/tmp/payout';
             if (!file_exists($basePath)) {
                 mkdir($basePath, 0777, true);
             }
             $path = $basePath . '/' . md5(time() . $this->file->getName());
             $this->filePath = $path;
             $this->fileName = $this->file->getName();
             $this->fileSize = $this->file->getSize();
             $this->file->saveAs($path);
         }
         $this->modifiedAt = date('Y-m-d H:i:s');
         return true;
     }
     return false;
 }
开发者ID:shnellpavel,项目名称:bcgroup_lk,代码行数:21,代码来源:PayoutTask.php

示例9: save

 /**
  * Saves a new image.
  * @param CUploadedFile $file the uploaded image.
  * @param CActiveRecord $owner the owner model.
  * @param string $name the image name. Available since 1.2.0
  * @param string $path the path to save the file to. Available since 1.2.1.
  * @return Image the image model.
  * @throws CException if saving the image fails.
  */
 public function save($file, $name = null, $path = null)
 {
     $trx = Yii::app()->db->beginTransaction();
     try {
         $image = new Image();
         $image->extension = strtolower($file->getExtensionName());
         $image->filename = $file->getName();
         $image->byteSize = $file->getSize();
         $image->mimeType = $file->getType();
         $image->createTime = new CDbExpression('NOW()');
         if (empty($name)) {
             $name = $file->getName();
             $name = substr($name, 0, strrpos($name, '.'));
         }
         $image->name = $this->normalizeString($name);
         if ($path !== null) {
             $image->path = trim($path, '/');
         }
         if ($image->save() === false) {
             throw new CException(__CLASS__ . ': Failed to save image! Record could not be saved.');
         }
         $path = $this->resolveImagePath($image);
         if (!file_exists($path) && !$this->createDirectory($path)) {
             throw new CException(__CLASS__ . ': Failed to save image! Directory could not be created.');
         }
         $path .= $this->resolveFileName($image);
         if ($file->saveAs($path) === false) {
             throw new CException(__CLASS__ . ': Failed to save image! File could not be saved.');
         }
         $trx->commit();
         return $image;
     } catch (CException $e) {
         $trx->rollback();
         throw $e;
     }
 }
开发者ID:rualatngua,项目名称:yii-image,代码行数:45,代码来源:Imager.php

示例10: validateFile

 /**
  * Internally validates a file object.
  * @param CModel $object the object being validated
  * @param string $attribute the attribute being validated
  * @param CUploadedFile $file uploaded file passed to check against a set of rules
  * @throws CException if failed to upload the file
  */
 protected function validateFile($object, $attribute, $file)
 {
     if (null === $file || ($error = $file->getError()) == UPLOAD_ERR_NO_FILE) {
         return $this->emptyAttribute($object, $attribute);
     } elseif ($error == UPLOAD_ERR_INI_SIZE || $error == UPLOAD_ERR_FORM_SIZE || $this->maxSize !== null && $file->getSize() > $this->maxSize) {
         $message = $this->tooLarge !== null ? $this->tooLarge : Yii::t('yii', 'The file "{file}" is too large. Its size cannot exceed {limit} bytes.');
         $this->addError($object, $attribute, $message, array('{file}' => $file->getName(), '{limit}' => $this->getSizeLimit()));
     } elseif ($error == UPLOAD_ERR_PARTIAL) {
         throw new CException(Yii::t('yii', 'The file "{file}" was only partially uploaded.', array('{file}' => $file->getName())));
     } elseif ($error == UPLOAD_ERR_NO_TMP_DIR) {
         throw new CException(Yii::t('yii', 'Missing the temporary folder to store the uploaded file "{file}".', array('{file}' => $file->getName())));
     } elseif ($error == UPLOAD_ERR_CANT_WRITE) {
         throw new CException(Yii::t('yii', 'Failed to write the uploaded file "{file}" to disk.', array('{file}' => $file->getName())));
     } elseif (defined('UPLOAD_ERR_EXTENSION') && $error == UPLOAD_ERR_EXTENSION) {
         // available for PHP 5.2.0 or above
         throw new CException(Yii::t('yii', 'A PHP extension stopped the file upload.'));
     }
     if ($this->minSize !== null && $file->getSize() < $this->minSize) {
         $message = $this->tooSmall !== null ? $this->tooSmall : Yii::t('yii', 'The file "{file}" is too small. Its size cannot be smaller than {limit} bytes.');
         $this->addError($object, $attribute, $message, array('{file}' => $file->getName(), '{limit}' => $this->minSize));
     }
     if ($this->types !== null) {
         if (is_string($this->types)) {
             $types = preg_split('/[\\s,]+/', strtolower($this->types), -1, PREG_SPLIT_NO_EMPTY);
         } else {
             $types = $this->types;
         }
         if (!in_array(strtolower($file->getExtensionName()), $types)) {
             $message = $this->wrongType !== null ? $this->wrongType : Yii::t('yii', 'The file "{file}" cannot be uploaded. Only files with these extensions are allowed: {extensions}.');
             $this->addError($object, $attribute, $message, array('{file}' => $file->getName(), '{extensions}' => implode(', ', $types)));
         }
     }
     if ($this->mimeTypes !== null) {
         if (function_exists('finfo_open')) {
             $mimeType = false;
             if ($info = finfo_open(defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME)) {
                 $mimeType = finfo_file($info, $file->getTempName());
             }
         } elseif (function_exists('mime_content_type')) {
             $mimeType = mime_content_type($file->getTempName());
         } else {
             throw new CException(Yii::t('yii', 'In order to use MIME-type validation provided by CFileValidator fileinfo PECL extension should be installed.'));
         }
         if (is_string($this->mimeTypes)) {
             $mimeTypes = preg_split('/[\\s,]+/', strtolower($this->mimeTypes), -1, PREG_SPLIT_NO_EMPTY);
         } else {
             $mimeTypes = $this->mimeTypes;
         }
         if ($mimeType === false || !in_array(strtolower($mimeType), $mimeTypes)) {
             $message = $this->wrongMimeType !== null ? $this->wrongMimeType : Yii::t('yii', 'The file "{file}" cannot be uploaded. Only files of these MIME-types are allowed: {mimeTypes}.');
             $this->addError($object, $attribute, $message, array('{file}' => $file->getName(), '{mimeTypes}' => implode(', ', $mimeTypes)));
         }
     }
 }
开发者ID:movoin,项目名称:yii-framework,代码行数:61,代码来源:CFileValidator.php

示例11: validateFile

 /**
  * Internally validates a file object.
  *
  * @param CModel $object the object being validated
  * @param string $attribute the attribute being validated
  * @param CUploadedFile $file uploaded file passed to check against a set of rules
  */
 protected function validateFile($object, $attribute, $file)
 {
     if (null === $file || ($error = $file->getError()) == UPLOAD_ERR_NO_FILE) {
         return $this->emptyAttribute($object, $attribute);
     } else {
         if ($error == UPLOAD_ERR_INI_SIZE || $error == UPLOAD_ERR_FORM_SIZE || $this->maxSize !== null && $file->getSize() > $this->maxSize) {
             $message = $this->tooLarge !== null ? $this->tooLarge : Yii::t('yii', 'The file "{file}" is too large. Its size cannot exceed {limit} bytes.');
             $this->addError($object, $attribute, $message, array('{file}' => $file->getName(), '{limit}' => $this->getSizeLimit()));
         } else {
             if ($error == UPLOAD_ERR_PARTIAL) {
                 throw new CException(Yii::t('yii', 'The file "{file}" was only partially uploaded.', array('{file}' => $file->getName())));
             } else {
                 if ($error == UPLOAD_ERR_NO_TMP_DIR) {
                     throw new CException(Yii::t('yii', 'Missing the temporary folder to store the uploaded file "{file}".', array('{file}' => $file->getName())));
                 } else {
                     if ($error == UPLOAD_ERR_CANT_WRITE) {
                         throw new CException(Yii::t('yii', 'Failed to write the uploaded file "{file}" to disk.', array('{file}' => $file->getName())));
                     } else {
                         if (defined('UPLOAD_ERR_EXTENSION') && $error == UPLOAD_ERR_EXTENSION) {
                             throw new CException(Yii::t('yii', 'File upload was stopped by extension.'));
                         }
                     }
                 }
             }
         }
     }
     if ($this->minSize !== null && $file->getSize() < $this->minSize) {
         $message = $this->tooSmall !== null ? $this->tooSmall : Yii::t('yii', 'The file "{file}" is too small. Its size cannot be smaller than {limit} bytes.');
         $this->addError($object, $attribute, $message, array('{file}' => $file->getName(), '{limit}' => $this->minSize));
     }
     if ($this->types !== null) {
         if (is_string($this->types)) {
             $types = preg_split('/[\\s,]+/', strtolower($this->types), -1, PREG_SPLIT_NO_EMPTY);
         } else {
             $types = $this->types;
         }
         if (!in_array(strtolower($file->getExtensionName()), $types)) {
             $message = $this->wrongType !== null ? $this->wrongType : Yii::t('yii', 'The file "{file}" cannot be uploaded. Only files with these extensions are allowed: {extensions}.');
             $this->addError($object, $attribute, $message, array('{file}' => $file->getName(), '{extensions}' => implode(', ', $types)));
         }
     }
 }
开发者ID:noxt,项目名称:business-keeper,代码行数:49,代码来源:CFileValidator.php

示例12: setUploadedFile

 public function setUploadedFile(CUploadedFile $cUploadedFile)
 {
     $this->file_name = $cUploadedFile->getName();
     $this->mime_type = $cUploadedFile->getType();
     $this->size = $cUploadedFile->getSize();
     $this->cUploadedFile = $cUploadedFile;
 }
开发者ID:alefernie,项目名称:intranet,代码行数:7,代码来源:File.php

示例13: generateUniqueName

 public function generateUniqueName()
 {
     $fileName = basename($this->image->getName(), $this->image->getExtensionName());
     return uniqid($fileName) . "." . $this->image->getExtensionName();
 }
开发者ID:jankichaudhari,项目名称:yii-site,代码行数:5,代码来源:BlogImage.php

示例14: store

 /**
  * Saves given CUploadedFiles
  *
  */
 public static function store(CUploadedFile $cUploadedFile)
 {
     // Santize Filename
     $filename = $cUploadedFile->getName();
     $filename = trim($filename);
     $filename = preg_replace("/[^a-z0-9_\\-s\\.]/i", "", $filename);
     $pathInfo = pathinfo($filename);
     if (strlen($pathInfo['filename']) > 60) {
         $pathInfo['filename'] = substr($pathInfo['filename'], 0, 60);
     }
     $filename = $pathInfo['filename'];
     if (isset($pathInfo['extension'])) {
         $filename .= "." . $pathInfo['extension'];
     }
     $file = new File();
     if (!self::HasValidExtension($filename)) {
         return false;
     }
     $file->file_name = $filename;
     $file->title = $cUploadedFile->getName();
     $file->mime_type = $cUploadedFile->getType();
     #$file->size = $cUploadedFile->getSize();
     if ($file->save()) {
         // Add File to Filebase
         $file->slurp($cUploadedFile->getTempName());
         return $file;
     } else {
         return;
     }
 }
开发者ID:ahdail,项目名称:humhub,代码行数:34,代码来源:File.php

示例15: beforeSave

 protected function beforeSave()
 {
     if ($this->isNewRecord) {
         $this->med_created = date('Y-m-d H:i:s');
         if (!$this->med_row) {
             throw new CDbException('Cant save the media if it does not belong to any record');
         }
         $sql = "SELECT IF(MAX(med_order) IS NOT NULL, MAX(med_order), 0) as max_ord  FROM " . $this->tableName() . " WHERE med_row = '" . $this->med_row . "' AND med_type = '" . $this->med_type . "'";
         $command = Yii::app()->db->createCommand($sql);
         $result = $command->queryRow();
         $this->med_order = $result['max_ord'] + 1;
     }
     if ($this->file) {
         $this->med_type = isset($this->otherMedia) && $this->otherMedia ? $this->otherMedia : self::TYPE_PHOTO;
         $fileTempName = $this->file->tempName;
         list($imgWidth, $imgHeight, $type, $attr) = getimagesize($fileTempName);
         if (strtolower($this->file->extensionName) == 'gif' && $imgHeight * $imgWidth > self::MAX_AVAILABLE_GIF_PIXEL_COUNT) {
             $this->addError('file', 'Sorry, but GIF image is too large!');
             return false;
         }
         $fileName = $this->generateUniqFileName();
         $this->med_realname = $this->file->getName();
         $this->med_filetype = $this->file->getType();
         $this->med_filesize = $this->file->getSize();
         $ext = $this->file->getExtensionName();
         $extension = '.' . $ext;
         $filePath = $this->getLocalPath();
         $this->med_file = $fileName . $extension;
         /** @var $imageTool \upload */
         $imageTool = Yii::app()->imagemod->load($fileTempName);
         $imageTool->file_new_name_body = $fileName;
         $imageTool->file_new_name_ext = $ext;
         $imageTool->process($filePath);
         $imageDimType = null;
         if ($imgHeight > $imgWidth) {
             //vertical image
             $imageDimType = 'vertical';
             if ($imgHeight > $this->resizeHeight) {
                 $imageTool = $this->resizeImageTool($imageTool, $imageDimType, $this->resizeHeight);
             }
         } else {
             //horizontal image
             $imageDimType = 'horizontal';
             if ($imgWidth > $this->resizeWidth) {
                 $imageTool = $this->resizeImageTool($imageTool, $imageDimType, $this->resizeWidth);
             }
         }
         $imageTool->file_new_name_body = $fileName . self::SUFFIX_ORIGINAL;
         $imageTool->file_new_name_ext = $ext;
         $imageTool->process($filePath);
         /*floorplan OR epc*/
         if (isset($this->otherMedia) && $this->otherMedia) {
             foreach ($this->otherMediaSizes as $suffix => $sizes) {
                 if ($imageDimType == 'vertical' && $imgHeight > $sizes['h']) {
                     $imageTool->image_resize = true;
                     $imageTool->image_ratio_x = true;
                     $imageTool->image_y = $sizes['h'];
                 } else {
                     if ($imageDimType == 'horizontal' && $imgWidth > $sizes['w']) {
                         $imageTool->image_resize = true;
                         $imageTool->image_ratio_y = true;
                         $imageTool->image_x = $sizes['w'];
                     }
                 }
                 $imageTool->file_new_name_body = $fileName . $suffix;
                 $imageTool->file_new_name_ext = $ext;
                 $imageTool->process($filePath);
             }
         } else {
             // photograph
             $croppedFilePath = '';
             if (isset($this->cropFactor['w'])) {
                 $imageTool->image_ratio_crop = true;
                 $cropWidth = $this->cropFactor['w'] * $imgWidth / $this->cropFactor['width'];
                 $top = $this->cropFactor['y'] * $imgHeight / $this->cropFactor['height'];
                 $left = $this->cropFactor['x'] * $imgWidth / $this->cropFactor['width'];
                 $right = $imgWidth - ($left + $cropWidth);
                 $bottom = $imgHeight - ($top + $cropWidth);
                 $imageTool->image_crop = array($top, $right, $bottom, $left);
                 $imageTool->file_new_name_body = $fileName . '_crop';
                 $imageTool->file_new_name_ext = $ext;
                 $imageTool->process($filePath);
                 // Load cropped file and resize
                 $croppedFilePath = $filePath . '/' . $fileName . '_crop' . $extension;
                 $imageTool = Yii::app()->imagemod->load($croppedFilePath);
             }
             foreach ($this->photoCropSizes as $suffix => $sizes) {
                 if ($suffix != '_original') {
                     if ($imageDimType == 'vertical') {
                         //horizontal image
                         if (!isset($this->cropFactor['h'])) {
                             $imageTool->image_ratio_crop = true;
                             $top = $bottom = 0;
                             $left = $right = ($imgWidth * $sizes['h'] / $imgHeight - $sizes['w']) / 2 + 1;
                             $imageTool->image_crop = array($top, $right, $bottom, $left);
                         }
                         $imageTool->image_resize = true;
                         $imageTool->image_y = $sizes['h'];
                         $imageTool->image_ratio_x = true;
                     } else {
//.........这里部分代码省略.........
开发者ID:jankichaudhari,项目名称:yii-site,代码行数:101,代码来源:Media.php


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