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


PHP IOHelper::cleanFilename方法代码示例

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


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

示例1: actionUploadLogo

 /**
  * Upload a logo for the admin panel.
  */
 public function actionUploadLogo()
 {
     $this->requireAjaxRequest();
     $this->requireAdmin();
     // Upload the file and drop it in the temporary folder
     $uploader = new \qqFileUploader();
     try {
         // Make sure a file was uploaded
         if ($uploader->file && $uploader->file->getSize()) {
             $folderPath = craft()->path->getTempUploadsPath();
             IOHelper::ensureFolderExists($folderPath);
             IOHelper::clearFolder($folderPath, true);
             $fileName = IOHelper::cleanFilename($uploader->file->getName());
             $uploader->file->save($folderPath . $fileName);
             // Test if we will be able to perform image actions on this image
             if (!craft()->images->setMemoryForImage($folderPath . $fileName)) {
                 IOHelper::deleteFile($folderPath . $fileName);
                 $this->returnErrorJson(Craft::t('The uploaded image is too large'));
             }
             craft()->images->cleanImage($folderPath . $fileName);
             $constraint = 500;
             list($width, $height) = getimagesize($folderPath . $fileName);
             // If the file is in the format badscript.php.gif perhaps.
             if ($width && $height) {
                 // Never scale up the images, so make the scaling factor always <= 1
                 $factor = min($constraint / $width, $constraint / $height, 1);
                 $html = craft()->templates->render('_components/tools/cropper_modal', array('imageUrl' => UrlHelper::getResourceUrl('tempuploads/' . $fileName), 'width' => round($width * $factor), 'height' => round($height * $factor), 'factor' => $factor));
                 $this->returnJson(array('html' => $html));
             }
         }
     } catch (Exception $exception) {
         $this->returnErrorJson($exception->getMessage());
     }
     $this->returnErrorJson(Craft::t('There was an error uploading your photo'));
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:38,代码来源:RebrandController.php

示例2: getTemplateByName

 /**
  * Get template file by its name
  * 		
  * @param  string $templateName Template file name
  * @return array               Returns template file information
  */
 public function getTemplateByName($templateName)
 {
     $template = [];
     $path = craft()->path->getPluginsPath() . 'formbuilder2/templates/email/templates/' . $templateName;
     $file = IOHelper::getFile($path);
     $template = ['fileName' => $file->getFileName(false), 'fileOriginalName' => $file->getFileName(), 'fileNameCleaned' => IOHelper::cleanFilename(IOHelper::getFileName($file->getRealPath(), false)), 'fileExtension' => $file->getExtension(), 'filePath' => $file->getRealPath(), 'fileContents' => $file->getContents()];
     return $template;
 }
开发者ID:roundhouse,项目名称:FormBuilder-2-Craft-CMS,代码行数:14,代码来源:FormBuilder2_TemplateService.php

示例3: cleanAssetName

 /**
  * Clean an Asset's filename.
  *
  * @param $fileName
  *
  * @return mixed
  */
 public static function cleanAssetName($fileName)
 {
     $separator = craft()->config->get('filenameWordSeparator');
     if (!is_string($separator)) {
         $separator = null;
     }
     return IOHelper::cleanFilename($fileName, false, $separator);
 }
开发者ID:kant312,项目名称:sop,代码行数:15,代码来源:AssetsHelper.php

示例4: run

 /**
  * Dump all tables
  *
  * @return string
  */
 public function run()
 {
     $this->_currentVersion = 'v' . Craft::getVersion() . '.' . Craft::getBuild();
     $result = $this->_processHeader();
     foreach (craft()->db->getSchema()->getTables() as $tableName => $val) {
         $result .= $this->_processTable($tableName);
     }
     $result .= $this->_processConstraints();
     $result .= $this->_processFooter();
     $fileName = IOHelper::cleanFilename(Craft::getSiteName()) . '_' . gmdate('ymd_His') . '_' . $this->_currentVersion . '.sql';
     $filePath = craft()->path->getDbBackupPath() . strtolower($fileName);
     IOHelper::writeToFile($filePath, $result);
     return $filePath;
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:19,代码来源:DbBackup.php

示例5: backupAllForms

 /**
  * Backup All Forms
  */
 public function backupAllForms()
 {
     $forms = FormBuilder2_FormRecord::model()->ordered()->findAll();
     $table = 'craft_formbuilder2_forms';
     if ($forms) {
         $this->_currentVersion = 'v' . craft()->getVersion() . '.' . craft()->getBuild();
         $siteName = IOHelper::cleanFilename(StringHelper::asciiString(craft()->getSiteName()));
         $fileName = ($siteName ? $siteName . '_' : '') . gmdate('ymd_His') . '_' . $this->_currentVersion . '.sql';
         $this->_filePath = craft()->path->getDbBackupPath() . StringHelper::toLowerCase($fileName);
         $this->_processHeader();
         $results = $this->_processResult($table);
         $this->_processConstraints();
         $this->_processFooter();
         $filepath = $this->_filePath;
         $this->_processFile($fileName, $filepath);
     } else {
         return false;
     }
 }
开发者ID:daituzhang,项目名称:craft-starter,代码行数:22,代码来源:FormBuilder2Service.php

示例6: getTemplateFiles

 public function getTemplateFiles()
 {
     $folderEmpty = true;
     if (IOHelper::isFolderEmpty(craft()->path->getPluginsPath() . 'formbuilder2/templates/email/layouts')) {
         throw new HttpException(404, Craft::t('Looks like you don\'t have any templates in your email/layouts folder.'));
     } else {
         $folderEmpty = false;
     }
     $fileList = IOHelper::getFolderContents(craft()->path->getPluginsPath() . 'formbuilder2/templates/email/layouts');
     $files = [];
     $filesModel = [];
     if (!$folderEmpty) {
         foreach ($fileList as $key => $file) {
             $files[$key] = ['fileName' => IOHelper::getFileName($file, false), 'fileOriginalName' => IOHelper::getFileName($file), 'fileNameCleaned' => IOHelper::cleanFilename(IOHelper::getFileName($file, false)), 'fileExtension' => IOHelper::getExtension($file), 'filePath' => $file, 'fileContents' => IOHelper::getFileContents($file)];
             $filesModel[] = FormBuilder2_FileModel::populateModel($files[$key]);
         }
     }
     return $filesModel;
 }
开发者ID:roundhouse,项目名称:FormBuilder-2-Craft-CMS,代码行数:19,代码来源:FormBuilder2_LayoutService.php

示例7: run

 /**
  * Triggers the database backup including all DML and DDL and writes it out to a file.
  *
  * @return string The path to the database backup file.
  */
 public function run()
 {
     // Normalize the ignored table names if there is a table prefix set.
     if (($tablePrefix = craft()->config->get('tablePrefix', ConfigFile::Db)) !== '') {
         foreach ($this->_ignoreDataTables as $key => $tableName) {
             $this->_ignoreDataTables[$key] = $tablePrefix . '_' . $tableName;
         }
     }
     $this->_currentVersion = 'v' . craft()->getVersion() . '.' . craft()->getBuild();
     $fileName = IOHelper::cleanFilename(craft()->getSiteName()) . '_' . gmdate('ymd_His') . '_' . $this->_currentVersion . '.sql';
     $this->_filePath = craft()->path->getDbBackupPath() . StringHelper::toLowerCase($fileName);
     $this->_processHeader();
     foreach (craft()->db->getSchema()->getTables() as $resultName => $val) {
         $this->_processResult($resultName);
     }
     $this->_processConstraints();
     $this->_processFooter();
     return $this->_filePath;
 }
开发者ID:webremote,项目名称:craft_boilerplate,代码行数:24,代码来源:DbBackup.php

示例8: actionSetTemplate

 public function actionSetTemplate()
 {
     $this->requirePostRequest();
     $this->requireAjaxRequest();
     $templatePath = craft()->request->getRequiredPost('templatePath');
     $folderContents = IOHelper::getFolderContents(craft()->path->getPluginsPath() . 'formbuilder2/templates/layouts/templates/');
     $theFile = '';
     if ($folderContents && $templatePath) {
         foreach ($folderContents as $key => $file) {
             $fileName = IOHelper::getFileName($file, false);
             if ($fileName == $templatePath) {
                 $theFile = IOHelper::getFile($file);
             }
         }
     }
     if ($theFile == '') {
         $this->returnErrorJson('No template with that name.');
     } else {
         $template = ['fileName' => $theFile->getFileName(false), 'fileOriginalName' => $theFile->getFileName(), 'fileNameCleaned' => IOHelper::cleanFilename(IOHelper::getFileName($theFile->getRealPath(), false)), 'fileExtension' => $theFile->getExtension(), 'filePath' => $theFile->getRealPath(), 'fileContents' => $theFile->getContents()];
         $this->returnJson(['success' => true, 'message' => Craft::t('Template is set.'), 'layout' => $template]);
     }
 }
开发者ID:roundhouse,项目名称:FormBuilder-2-Craft-CMS,代码行数:22,代码来源:FormBuilder2_LayoutController.php

示例9: cleanAssetName

 /**
  * Clean an Asset's filename.
  *
  * @param $name
  * @param bool $isFilename if set to true (default), will separate extension
  *                         and clean the filename separately.
  *
  * @return mixed
  */
 public static function cleanAssetName($name, $isFilename = true)
 {
     if ($isFilename) {
         $baseName = IOHelper::getFileName($name, false);
         $extension = '.' . IOHelper::getExtension($name);
     } else {
         $baseName = $name;
         $extension = '';
     }
     $separator = craft()->config->get('filenameWordSeparator');
     if (!is_string($separator)) {
         $separator = null;
     }
     $baseName = IOHelper::cleanFilename($baseName, craft()->config->get('convertFilenamesToAscii'), $separator);
     if ($isFilename && empty($baseName)) {
         $baseName = '-';
     }
     return $baseName . $extension;
 }
开发者ID:jmstan,项目名称:craft-website,代码行数:28,代码来源:AssetsHelper.php

示例10: saveUserPhoto

 /**
  * Crops and saves a user’s photo.
  *
  * @param string    $fileName The name of the file.
  * @param Image     $image    The image.
  * @param UserModel $user     The user.
  *
  * @throws \Exception
  * @return bool Whether the photo was saved successfully.
  */
 public function saveUserPhoto($fileName, Image $image, UserModel $user)
 {
     $userName = IOHelper::cleanFilename($user->username);
     $userPhotoFolder = craft()->path->getUserPhotosPath() . $userName . '/';
     $targetFolder = $userPhotoFolder . 'original/';
     IOHelper::ensureFolderExists($userPhotoFolder);
     IOHelper::ensureFolderExists($targetFolder);
     $targetPath = $targetFolder . AssetsHelper::cleanAssetName($fileName);
     $result = $image->saveAs($targetPath);
     if ($result) {
         IOHelper::changePermissions($targetPath, craft()->config->get('defaultFilePermissions'));
         $record = UserRecord::model()->findById($user->id);
         $record->photo = $fileName;
         $record->save();
         $user->photo = $fileName;
         return true;
     }
     return false;
 }
开发者ID:webremote,项目名称:craft_boilerplate,代码行数:29,代码来源:UsersService.php

示例11: getResourcePath

 /**
  * Resolves a resource path to the actual file system path, or returns false if the resource cannot be found.
  *
  * @param string $path
  * @return string
  */
 public function getResourcePath($path)
 {
     $segs = explode('/', $path);
     // Special resource routing
     if (isset($segs[0])) {
         switch ($segs[0]) {
             case 'js':
                 // Route to js/compressed/ if useCompressedJs is enabled
                 if (craft()->config->get('useCompressedJs')) {
                     array_splice($segs, 1, 0, 'compressed');
                     $path = implode('/', $segs);
                 }
                 break;
             case 'userphotos':
                 if (isset($segs[1]) && $segs[1] == 'temp') {
                     if (!isset($segs[2])) {
                         return false;
                     }
                     return craft()->path->getTempUploadsPath() . 'userphotos/' . $segs[2] . '/' . $segs[3];
                 } else {
                     if (!isset($segs[3])) {
                         return false;
                     }
                     $username = IOHelper::cleanFilename($segs[1]);
                     $size = IOHelper::cleanFilename($segs[2]);
                     $filename = IOHelper::cleanFilename($segs[3]);
                     $userPhotosPath = craft()->path->getUserPhotosPath() . $username . '/';
                     $sizedPhotoFolder = $userPhotosPath . $size . '/';
                     $sizedPhotoPath = $sizedPhotoFolder . $filename;
                     // If the photo doesn't exist at this size, create it.
                     if (!IOHelper::fileExists($sizedPhotoPath)) {
                         $originalPhotoPath = $userPhotosPath . 'original/' . $filename;
                         if (!IOHelper::fileExists($originalPhotoPath)) {
                             return false;
                         }
                         IOHelper::ensureFolderExists($sizedPhotoFolder);
                         craft()->images->loadImage($originalPhotoPath)->resize($size)->saveAs($sizedPhotoPath);
                     }
                     return $sizedPhotoPath;
                 }
             case 'tempuploads':
                 array_shift($segs);
                 return craft()->path->getTempUploadsPath() . implode('/', $segs);
             case 'assetthumbs':
                 if (empty($segs[1]) || empty($segs[2]) || !is_numeric($segs[1]) || !is_numeric($segs[2])) {
                     return false;
                 }
                 $fileModel = craft()->assets->getFileById($segs[1]);
                 if (empty($fileModel)) {
                     return false;
                 }
                 $sourceType = craft()->assetSources->getSourceTypeById($fileModel->sourceId);
                 $size = $segs[2];
                 $thumbFolder = craft()->path->getAssetsThumbsPath() . $size . '/';
                 IOHelper::ensureFolderExists($thumbFolder);
                 $thumbPath = $thumbFolder . $fileModel->id . '.' . pathinfo($fileModel->filename, PATHINFO_EXTENSION);
                 if (!IOHelper::fileExists($thumbPath)) {
                     $sourcePath = $sourceType->getImageSourcePath($fileModel);
                     if (!IOHelper::fileExists($sourcePath)) {
                         return false;
                     }
                     craft()->images->loadImage($sourcePath)->scaleAndCrop($size, $size)->saveAs($thumbPath);
                 }
                 return $thumbPath;
             case 'icons':
                 if (empty($segs[1]) || empty($segs[2]) || !is_numeric($segs[2]) || !preg_match('/^(?P<extension>[a-z_0-9]+)/i', $segs[1])) {
                     return false;
                 }
                 $ext = strtolower($segs[1]);
                 $size = $segs[2];
                 $iconPath = $this->_getIconPath($ext, $size);
                 return $iconPath;
             case 'logo':
                 return craft()->path->getStoragePath() . implode('/', $segs);
         }
     }
     // Check app/resources folder first.
     $appResourcePath = craft()->path->getResourcesPath() . $path;
     if (IOHelper::fileExists($appResourcePath)) {
         return $appResourcePath;
     }
     // See if the first segment is a plugin handle.
     if (isset($segs[0])) {
         $pluginResourcePath = craft()->path->getPluginsPath() . $segs[0] . '/' . 'resources/' . implode('/', array_splice($segs, 1));
         if (IOHelper::fileExists($pluginResourcePath)) {
             return $pluginResourcePath;
         }
     }
     // Maybe a plugin wants to do something custom with this URL
     $pluginPaths = craft()->plugins->call('getResourcePath', array($path));
     foreach ($pluginPaths as $path) {
         if ($path && IOHelper::fileExists($path)) {
             return $path;
         }
//.........这里部分代码省略.........
开发者ID:kentonquatman,项目名称:portfolio,代码行数:101,代码来源:ResourcesService.php

示例12: createFolder

 /**
  * Create a subfolder.
  *
  * @param AssetFolderModel $parentFolder
  * @param $folderName
  * @return AssetOperationResponseModel
  * @throws Exception
  */
 public function createFolder(AssetFolderModel $parentFolder, $folderName)
 {
     $folderName = IOHelper::cleanFilename($folderName);
     // If folder exists in DB or physically, bail out
     if (craft()->assets->findFolder(array('parentId' => $parentFolder->id, 'name' => $folderName)) || $this->_sourceFolderExists($parentFolder, $folderName)) {
         throw new Exception(Craft::t('A folder already exists with that name!'));
     }
     if (!$this->_createSourceFolder($parentFolder, $folderName)) {
         throw new Exception(Craft::t('There was an error while creating the folder.'));
     }
     $newFolder = new AssetFolderModel();
     $newFolder->sourceId = $parentFolder->sourceId;
     $newFolder->parentId = $parentFolder->id;
     $newFolder->name = $folderName;
     $newFolder->fullPath = $parentFolder->fullPath . $folderName . '/';
     $folderId = craft()->assets->storeFolder($newFolder);
     $response = new AssetOperationResponseModel();
     return $response->setSuccess()->setDataItem('folderId', $folderId)->setDataItem('parentId', $parentFolder->id)->setDataItem('folderName', $folderName);
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:27,代码来源:BaseAssetSourceType.php

示例13: actionSendSupportRequest


//.........这里部分代码省略.........
                     $zipFile = $this->_createZip();
                 }
                 if ($getHelpModel->attachLogs && IOHelper::folderExists(craft()->path->getLogPath())) {
                     // Grab it all.
                     $logFolderContents = IOHelper::getFolderContents(craft()->path->getLogPath());
                     foreach ($logFolderContents as $file) {
                         // Make sure it's a file.
                         if (IOHelper::fileExists($file)) {
                             Zip::add($zipFile, $file, craft()->path->getStoragePath());
                         }
                     }
                 }
                 if ($getHelpModel->attachDbBackup && IOHelper::folderExists(craft()->path->getDbBackupPath())) {
                     // Make a fresh database backup of the current schema/data. We want all data from all tables
                     // for debugging.
                     craft()->db->backup();
                     $backups = IOHelper::getLastModifiedFiles(craft()->path->getDbBackupPath(), 3);
                     foreach ($backups as $backup) {
                         if (IOHelper::getExtension($backup) == 'sql') {
                             Zip::add($zipFile, $backup, craft()->path->getStoragePath());
                         }
                     }
                 }
             }
             if ($getHelpModel->attachment) {
                 // If we don't have a zip file yet, create one now.
                 if (!$zipFile) {
                     $zipFile = $this->_createZip();
                 }
                 $tempFolder = craft()->path->getTempPath() . StringHelper::UUID() . '/';
                 if (!IOHelper::folderExists($tempFolder)) {
                     IOHelper::createFolder($tempFolder);
                 }
                 $tempFile = $tempFolder . $getHelpModel->attachment->getName();
                 $getHelpModel->attachment->saveAs($tempFile);
                 // Make sure it actually saved.
                 if (IOHelper::fileExists($tempFile)) {
                     Zip::add($zipFile, $tempFile, $tempFolder);
                 }
             }
             if ($getHelpModel->attachTemplates) {
                 // If we don't have a zip file yet, create one now.
                 if (!$zipFile) {
                     $zipFile = $this->_createZip();
                 }
                 if (IOHelper::folderExists(craft()->path->getLogPath())) {
                     // Grab it all.
                     $templateFolderContents = IOHelper::getFolderContents(craft()->path->getSiteTemplatesPath());
                     foreach ($templateFolderContents as $file) {
                         // Make sure it's a file.
                         if (IOHelper::fileExists($file)) {
                             $templateFolderName = IOHelper::getFolderName(craft()->path->getSiteTemplatesPath(), false);
                             $siteTemplatePath = craft()->path->getSiteTemplatesPath();
                             $tempPath = substr($siteTemplatePath, 0, strlen($siteTemplatePath) - strlen($templateFolderName) - 1);
                             Zip::add($zipFile, $file, $tempPath);
                         }
                     }
                 }
             }
             if ($zipFile) {
                 $requestParams['File1_sFilename'] = 'SupportAttachment-' . IOHelper::cleanFilename(craft()->getSiteName()) . '.zip';
                 $requestParams['File1_sFileMimeType'] = 'application/zip';
                 $requestParams['File1_bFileBody'] = base64_encode(IOHelper::getFileContents($zipFile));
                 // Bump the default timeout because of the attachment.
                 $hsParams['callTimeout'] = 120;
             }
             // Grab the license.key file.
             if (IOHelper::fileExists(craft()->path->getLicenseKeyPath())) {
                 $requestParams['File2_sFilename'] = 'license.key';
                 $requestParams['File2_sFileMimeType'] = 'text/plain';
                 $requestParams['File2_bFileBody'] = base64_encode(IOHelper::getFileContents(craft()->path->getLicenseKeyPath()));
             }
         } catch (\Exception $e) {
             Craft::log('Tried to attach debug logs to a support request and something went horribly wrong: ' . $e->getMessage(), LogLevel::Warning);
             // There was a problem zipping, so reset the params and just send the email without the attachment.
             $requestParams = $requestParamDefaults;
         }
         require_once craft()->path->getLibPath() . 'HelpSpotAPI.php';
         $hsapi = new \HelpSpotAPI($hsParams);
         $result = $hsapi->requestCreate($requestParams);
         if ($result) {
             if ($zipFile) {
                 if (IOHelper::fileExists($zipFile)) {
                     IOHelper::deleteFile($zipFile);
                 }
             }
             if ($tempFolder) {
                 IOHelper::clearFolder($tempFolder);
                 IOHelper::deleteFolder($tempFolder);
             }
             $success = true;
         } else {
             $hsErrors = array_filter(preg_split("/(\r\n|\n|\r)/", $hsapi->errors));
             $errors = array('Support' => $hsErrors);
         }
     } else {
         $errors = $getHelpModel->getErrors();
     }
     $this->renderTemplate('_components/widgets/GetHelp/response', array('success' => $success, 'errors' => JsonHelper::encode($errors), 'widgetId' => $widgetId));
 }
开发者ID:jmstan,项目名称:craft-website,代码行数:101,代码来源:DashboardController.php

示例14: cleanAssetName

 /**
  * Clean an Asset's filename.
  *
  * @param $name
  * @param bool $isFilename         if set to true (default), will separate extension
  *                                 and clean the filename separately.
  * @param bool $preventPluginHooks if set to true, will prevent plugins from modifying
  *                                 the asset name.
  *
  * @return mixed
  */
 public static function cleanAssetName($name, $isFilename = true, $preventPluginModifications = false)
 {
     if ($isFilename) {
         $baseName = IOHelper::getFileName($name, false);
         $extension = '.' . IOHelper::getExtension($name);
     } else {
         $baseName = $name;
         $extension = '';
     }
     $separator = craft()->config->get('filenameWordSeparator');
     if (!is_string($separator)) {
         $separator = null;
     }
     if (!$preventPluginModifications) {
         $pluginModifiedAssetName = craft()->plugins->callFirst('modifyAssetFilename', array($baseName), true);
         // Use the plugin-modified name, if anyone was up to the task.
         $baseName = $pluginModifiedAssetName ?: $baseName;
     }
     $baseName = IOHelper::cleanFilename($baseName, craft()->config->get('convertFilenamesToAscii'), $separator);
     if ($isFilename && empty($baseName)) {
         $baseName = '-';
     }
     return $baseName . $extension;
 }
开发者ID:codeforamerica,项目名称:oakland-beta,代码行数:35,代码来源:AssetsHelper.php

示例15: _insertFileInFolder

 /**
  * Insert a file from path in folder.
  *
  * @param AssetFolderModel $folder
  * @param $filePath
  * @param $fileName
  * @return AssetOperationResponseModel
  * @throws Exception
  */
 protected function _insertFileInFolder(AssetFolderModel $folder, $filePath, $fileName)
 {
     $targetFolder = $this->_getSourceFileSystemPath() . $folder->fullPath;
     // Make sure the folder exists.
     if (!IOHelper::folderExists($targetFolder)) {
         throw new Exception(Craft::t('The “File System Path” specified for this asset source does not appear to exist.'));
     }
     // Make sure the folder is writable
     if (!IOHelper::isWritable($targetFolder)) {
         throw new Exception(Craft::t('Craft is not able to write to the “File System Path” specified for this asset source.'));
     }
     $fileName = IOHelper::cleanFilename($fileName);
     $targetPath = $targetFolder . $fileName;
     $extension = IOHelper::getExtension($fileName);
     if (!IOHelper::isExtensionAllowed($extension)) {
         throw new Exception(Craft::t('This file type is not allowed'));
     }
     if (IOHelper::fileExists($targetPath)) {
         $response = new AssetOperationResponseModel();
         return $response->setPrompt($this->_getUserPromptOptions($fileName))->setDataItem('fileName', $fileName);
     }
     if (!IOHelper::copyFile($filePath, $targetPath)) {
         throw new Exception(Craft::t('Could not copy file to target destination'));
     }
     IOHelper::changePermissions($targetPath, IOHelper::getWritableFilePermissions());
     $response = new AssetOperationResponseModel();
     return $response->setSuccess()->setDataItem('filePath', $targetPath);
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:37,代码来源:LocalAssetSourceType.php


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