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


PHP IOHelper::createFile方法代码示例

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


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

示例1: download

 /**
  * Download zipfile.
  *
  * @param array  $files
  * @param string $filename
  *
  * @return string
  */
 public function download($files, $filename)
 {
     // Get assets
     $criteria = craft()->elements->getCriteria(ElementType::Asset);
     $criteria->id = $files;
     $criteria->limit = null;
     $assets = $criteria->find();
     // Set destination zip
     $destZip = craft()->path->getTempPath() . $filename . '_' . time() . '.zip';
     // Create the zipfile
     IOHelper::createFile($destZip);
     // Loop through assets
     foreach ($assets as $asset) {
         // Get asset source
         $source = $asset->getSource();
         // Get asset source type
         $sourceType = $source->getSourceType();
         // Get asset file
         $file = $sourceType->getLocalCopy($asset);
         // Add to zip
         Zip::add($destZip, $file, dirname($file));
     }
     // Return zip destination
     return $destZip;
 }
开发者ID:brammittendorff,项目名称:zipassets,代码行数:33,代码来源:ZipAssetsService.php

示例2: performAction

 /**
  * Performs the tool's action.
  *
  * @param array $params
  * @return array
  */
 public function performAction($params = array())
 {
     $file = craft()->db->backup();
     if (IOHelper::fileExists($file) && isset($params['downloadBackup']) && (bool) $params['downloadBackup']) {
         $destZip = craft()->path->getTempPath() . IOHelper::getFileName($file, false) . '.zip';
         if (IOHelper::fileExists($destZip)) {
             IOHelper::deleteFile($destZip, true);
         }
         IOHelper::createFile($destZip);
         if (Zip::add($destZip, $file, craft()->path->getDbBackupPath())) {
             return array('backupFile' => IOHelper::getFileName($destZip, false));
         }
     }
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:20,代码来源:DbBackupTool.php

示例3: compress

 /**
  * @param $source
  * @param $destZip
  *
  * @return bool 'true' if the zip was successfully created, 'false' if not.
  */
 public static function compress($source, $destZip)
 {
     $source = IOHelper::normalizePathSeparators($source);
     $destZip = IOHelper::normalizePathSeparators($destZip);
     if (!IOHelper::folderExists($source) && !IOHelper::fileExists($destZip)) {
         Craft::log('Tried to zip the contents of ' . $source . ' to ' . $destZip . ', but the source path does not exist.', LogLevel::Error);
         return false;
     }
     if (IOHelper::fileExists($destZip)) {
         IOHelper::deleteFile($destZip);
     }
     IOHelper::createFile($destZip);
     craft()->config->maxPowerCaptain();
     $zip = static::_getZipInstance($destZip);
     return $zip->zip(IOHelper::getRealPath($source), IOHelper::getRealPath($destZip));
 }
开发者ID:jmstan,项目名称:craft-website,代码行数:22,代码来源:Zip.php

示例4: performAction

 /**
  * @inheritDoc ITool::performAction()
  *
  * @param array $params
  *
  * @return array
  */
 public function performAction($params = array())
 {
     // In addition to the default tables we want to ignore data in, we also don't care about data in the session
     // table in this tools' case.
     $file = craft()->db->backup(array('sessions'));
     if (IOHelper::fileExists($file) && isset($params['downloadBackup']) && (bool) $params['downloadBackup']) {
         $destZip = craft()->path->getTempPath() . IOHelper::getFileName($file, false) . '.zip';
         if (IOHelper::fileExists($destZip)) {
             IOHelper::deleteFile($destZip, true);
         }
         IOHelper::createFile($destZip);
         if (Zip::add($destZip, $file, craft()->path->getDbBackupPath())) {
             return array('backupFile' => IOHelper::getFileName($destZip, false));
         }
     }
 }
开发者ID:kant312,项目名称:sop,代码行数:23,代码来源:DbBackupTool.php

示例5: finish

 /**
  * Finish importing.
  *
  * @param array  $settings
  * @param string $backup
  */
 public function finish($settings, $backup)
 {
     craft()->import_history->end($settings['history'], ImportModel::StatusFinished);
     if ($settings['email']) {
         // Gather results
         $results = array('success' => $settings['rows'], 'errors' => array());
         // Gather errors
         foreach ($this->log as $line => $result) {
             $results['errors'][$line] = $result;
         }
         // Recalculate successful results
         $results['success'] -= count($results['errors']);
         // Prepare the mail
         $email = new EmailModel();
         $emailSettings = craft()->email->getSettings();
         $email->toEmail = $emailSettings['emailAddress'];
         // Get current user
         $currentUser = craft()->userSession->getUser();
         // Zip the backup
         if ($currentUser->can('backup') && $settings['backup'] && IOHelper::fileExists($backup)) {
             $destZip = craft()->path->getTempPath() . IOHelper::getFileName($backup, false) . '.zip';
             if (IOHelper::fileExists($destZip)) {
                 IOHelper::deleteFile($destZip, true);
             }
             IOHelper::createFile($destZip);
             if (Zip::add($destZip, $backup, craft()->path->getDbBackupPath())) {
                 $backup = $destZip;
             }
         }
         // Set email content
         $email->subject = Craft::t('The import task is finished');
         $email->htmlBody = TemplateHelper::getRaw(craft()->templates->render('import/_email', array('results' => $results, 'backup' => $backup)));
         // Send it
         craft()->email->sendEmail($email);
     }
 }
开发者ID:ianshea,项目名称:import,代码行数:42,代码来源:ImportService.php

示例6: actionSendSupportRequest

 /**
  * Creates a new support ticket for the GetHelp widget.
  */
 public function actionSendSupportRequest()
 {
     $this->requirePostRequest();
     $this->requireAjaxRequest();
     craft()->config->maxPowerCaptain();
     $getHelpModel = new GetHelpModel();
     $getHelpModel->fromEmail = craft()->request->getPost('fromEmail');
     $getHelpModel->message = craft()->request->getPost('message');
     $getHelpModel->attachDebugFiles = (bool) craft()->request->getPost('attachDebugFiles');
     if ($getHelpModel->validate()) {
         $user = craft()->userSession->getUser();
         $requestParamDefaults = array('sFirstName' => $user->getFriendlyName(), 'sLastName' => $user->lastName ? $user->lastName : 'Doe', 'sEmail' => $getHelpModel->fromEmail, 'tNote' => $getHelpModel->message);
         $requestParams = $requestParamDefaults;
         $hsParams = array('helpSpotApiURL' => 'https://support.pixelandtonic.com/api/index.php');
         try {
             if ($getHelpModel->attachDebugFiles) {
                 $tempZipFile = craft()->path->getTempPath() . StringHelper::UUID() . '.zip';
                 IOHelper::createFile($tempZipFile);
                 if (IOHelper::folderExists(craft()->path->getLogPath())) {
                     // Grab the latest log file.
                     Zip::add($tempZipFile, craft()->path->getLogPath() . 'craft.log', craft()->path->getStoragePath());
                     // Grab the most recent rolled-over log file, if one exists.
                     if (IOHelper::fileExists(craft()->path->getLogPath() . 'craft.log.1')) {
                         Zip::add($tempZipFile, craft()->path->getLogPath() . 'craft.log.1', craft()->path->getStoragePath());
                     }
                     // Grab the phperrors log file, if it exists.
                     if (IOHelper::fileExists(craft()->path->getLogPath() . 'phperrors.log')) {
                         Zip::add($tempZipFile, craft()->path->getLogPath() . 'phperrors.log', craft()->path->getStoragePath());
                     }
                 }
                 if (IOHelper::folderExists(craft()->path->getDbBackupPath())) {
                     // Make a fresh database backup of the current schema/data.
                     craft()->db->backup();
                     $contents = IOHelper::getFolderContents(craft()->path->getDbBackupPath());
                     rsort($contents);
                     // Only grab the most recent 3 sorted by timestamp.
                     for ($counter = 0; $counter <= 2; $counter++) {
                         if (isset($contents[$counter])) {
                             Zip::add($tempZipFile, $contents[$counter], craft()->path->getStoragePath());
                         }
                     }
                 }
                 $requestParams['File1_sFilename'] = 'SupportAttachment.zip';
                 $requestParams['File1_sFileMimeType'] = 'application/zip';
                 $requestParams['File1_bFileBody'] = base64_encode(IOHelper::getFileContents($tempZipFile));
                 // Bump the default timeout because of the attachment.
                 $hsParams['callTimeout'] = 120;
             }
         } 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 ($getHelpModel->attachDebugFiles) {
                 if (IOHelper::fileExists($tempZipFile)) {
                     IOHelper::deleteFile($tempZipFile);
                 }
             }
             $this->returnJson(array('success' => true));
         } else {
             $hsErrors = array_filter(preg_split("/(\r\n|\n|\r)/", $hsapi->errors));
             $this->returnJson(array('errors' => array('Support' => $hsErrors)));
         }
     } else {
         $this->returnJson(array('errors' => $getHelpModel->getErrors()));
     }
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:74,代码来源:DashboardController.php

示例7: _createZip

 /**
  * @return string
  */
 private function _createZip()
 {
     $zipFile = craft()->path->getTempPath() . StringHelper::UUID() . '.zip';
     IOHelper::createFile($zipFile);
     return $zipFile;
 }
开发者ID:jmstan,项目名称:craft-website,代码行数:9,代码来源:DashboardController.php

示例8: getTempFilePath

 /**
  * Get a temporary file path.
  *
  * @param string $extension extension to use. "tmp" by default.
  *
  * @return mixed
  */
 public static function getTempFilePath($extension = 'tmp')
 {
     $extension = strpos($extension, '.') !== false ? pathinfo($extension, PATHINFO_EXTENSION) : $extension;
     $fileName = uniqid('assets', true) . '.' . $extension;
     return IOHelper::createFile(craft()->path->getTempPath() . $fileName)->getRealPath();
 }
开发者ID:codeforamerica,项目名称:oakland-beta,代码行数:13,代码来源:AssetsHelper.php

示例9: getTempFilePath

 /**
  * Get a temporary file path.
  *
  * @param string $extension extension to use. "tmp" by default.
  * @return mixed
  */
 public static function getTempFilePath($extension = 'tmp')
 {
     $extension = preg_replace('/[^a-z]/i', '', $extension);
     $fileName = uniqid('assets', true) . '.' . $extension;
     return IOHelper::createFile(craft()->path->getTempPath() . $fileName)->getRealPath();
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:12,代码来源:AssetsHelper.php

示例10: saveBackup

 /**
  * @codeCoverageIgnore
  *
  * @param array     $settings
  * @param string    $backup
  * @param UserModel $currentUser
  *
  * @return string Backup filename
  */
 protected function saveBackup($settings, $backup, $currentUser)
 {
     if ($currentUser->can('backup') && $settings['backup'] && IOHelper::fileExists($backup)) {
         $destZip = craft()->path->getTempPath() . IOHelper::getFileName($backup, false) . '.zip';
         if (IOHelper::fileExists($destZip)) {
             IOHelper::deleteFile($destZip, true);
         }
         IOHelper::createFile($destZip);
         if (Zip::add($destZip, $backup, craft()->path->getDbBackupPath())) {
             $backup = $destZip;
         }
     }
     return $backup;
 }
开发者ID:transomdesign,项目名称:transom-craft-starter,代码行数:23,代码来源:ImportService.php

示例11: _exportSubmissionToZip

 /**
  * Export a submission to the export's zip file.
  *
  * @param AmForms_ExportModel     $export
  * @param AmForms_SubmissionModel $submission
  */
 private function _exportSubmissionToZip(AmForms_ExportModel $export, AmForms_SubmissionModel $submission)
 {
     // Get submission content
     $content = craft()->amForms_submissions->getSubmissionEmailBody($submission);
     // Create submission file
     $fileName = IOHelper::cleanFilename($submission->title);
     $fileExtension = '.html';
     $folder = $this->_getExportPath();
     $file = $folder . $fileName . $fileExtension;
     $counter = 1;
     while (!IOHelper::createFile($file)) {
         $file = $folder . $fileName . $counter . $fileExtension;
         $counter++;
     }
     // Add content to file
     file_put_contents($file, $content);
     // Add file to zip
     Zip::add($export->file, $file, $folder);
     // Find possible assets
     foreach ($this->_exportFields[$export->id] as $fieldHandle => $field) {
         if (is_array($field)) {
             $field = (object) $field;
             // Fix standard fields
         }
         if ($field->type == 'Assets') {
             foreach ($submission->{$fieldHandle}->find() as $asset) {
                 $assetPath = craft()->amForms->getPathForAsset($asset);
                 if (IOHelper::fileExists($assetPath . $asset->filename)) {
                     Zip::add($export->file, $assetPath . $asset->filename, $assetPath);
                 }
             }
         }
     }
     // Remove submission file now that's in the zip
     IOHelper::deleteFile($file);
 }
开发者ID:webremote,项目名称:amforms,代码行数:42,代码来源:AmForms_ExportsService.php


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