本文整理汇总了PHP中IOHelper::getFileContents方法的典型用法代码示例。如果您正苦于以下问题:PHP IOHelper::getFileContents方法的具体用法?PHP IOHelper::getFileContents怎么用?PHP IOHelper::getFileContents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IOHelper
的用法示例。
在下文中一共展示了IOHelper::getFileContents方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionDownloadBackupFile
/**
* Returns a database backup zip file to the browser.
*
* @return null
*/
public function actionDownloadBackupFile()
{
$fileName = craft()->request->getRequiredQuery('fileName');
if (($filePath = IOHelper::fileExists(craft()->path->getTempPath() . $fileName . '.zip')) == true) {
craft()->request->sendFile(IOHelper::getFileName($filePath), IOHelper::getFileContents($filePath), array('forceDownload' => true));
}
}
示例2: actionDownloadFile
/**
* Downloads a file and cleans up old temporary assets
*/
public function actionDownloadFile()
{
// Clean up temp assets files that are more than a day old
$fileResults = array();
$files = IOHelper::getFiles(craft()->path->getTempPath(), true);
foreach ($files as $file) {
$lastModifiedTime = IOHelper::getLastTimeModified($file, true);
if (substr(IOHelper::getFileName($file, false, true), 0, 6) === "assets" && DateTimeHelper::currentTimeStamp() - $lastModifiedTime->getTimestamp() >= 86400) {
IOHelper::deleteFile($file);
}
}
// Sort out the file we want to download
$id = craft()->request->getParam('id');
$criteria = craft()->elements->getCriteria(ElementType::Asset);
$criteria->id = $id;
$asset = $criteria->first();
if ($asset) {
// Get a local copy of the file
$sourceType = craft()->assetSources->getSourceTypeById($asset->sourceId);
$localCopy = $sourceType->getLocalCopy($asset);
// Send it to the browser
craft()->request->sendFile($asset->filename, IOHelper::getFileContents($localCopy), array('forceDownload' => true));
craft()->end();
}
}
示例3: 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 zip
$zip = new \ZipArchive();
// Open zip
if ($zip->open($destZip, $zip::CREATE) === true) {
// 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->addFromString($asset->filename, IOHelper::getFileContents($file));
// Remove the file
IOHelper::deleteFile($file);
}
// Close zip
$zip->close();
// Return zip destination
return $destZip;
}
// Something went wrong
throw new Exception(Craft::t('Failed to generate the zipfile'));
}
示例4: nav
/**
* Get the sections of the CP.
*
* @return array
*/
public function nav($iconSize = 32)
{
$nav['dashboard'] = array('label' => Craft::t('Dashboard'), 'icon' => 'gauge');
if (craft()->sections->getTotalEditableSections()) {
$nav['entries'] = array('label' => Craft::t('Entries'), 'icon' => 'section');
}
$globals = craft()->globals->getEditableSets();
if ($globals) {
$nav['globals'] = array('label' => Craft::t('Globals'), 'url' => 'globals/' . $globals[0]->handle, 'icon' => 'globe');
}
if (craft()->categories->getEditableGroupIds()) {
$nav['categories'] = array('label' => Craft::t('Categories'), 'icon' => 'categories');
}
if (craft()->assetSources->getTotalViewableSources()) {
$nav['assets'] = array('label' => Craft::t('Assets'), 'icon' => 'assets');
}
if (craft()->getEdition() == Craft::Pro && craft()->userSession->checkPermission('editUsers')) {
$nav['users'] = array('label' => Craft::t('Users'), 'icon' => 'users');
}
// Add any Plugin nav items
$plugins = craft()->plugins->getPlugins();
foreach ($plugins as $plugin) {
if ($plugin->hasCpSection()) {
$pluginHandle = $plugin->getClassHandle();
if (craft()->userSession->checkPermission('accessPlugin-' . $pluginHandle)) {
$lcHandle = StringHelper::toLowerCase($pluginHandle);
$iconPath = craft()->path->getPluginsPath() . $lcHandle . '/resources/icon-mask.svg';
if (IOHelper::fileExists($iconPath)) {
$iconSvg = IOHelper::getFileContents($iconPath);
} else {
$iconSvg = false;
}
$nav[$lcHandle] = array('label' => $plugin->getName(), 'iconSvg' => $iconSvg);
}
}
}
if (craft()->userSession->isAdmin()) {
$nav['settings'] = array('label' => Craft::t('Settings'), 'icon' => 'settings');
}
// Allow plugins to modify the nav
craft()->plugins->call('modifyCpNav', array(&$nav));
// Figure out which item is selected, and normalize the items
$firstSegment = craft()->request->getSegment(1);
if ($firstSegment == 'myaccount') {
$firstSegment = 'users';
}
foreach ($nav as $handle => &$item) {
if (is_string($item)) {
$item = array('label' => $item);
}
$item['sel'] = $handle == $firstSegment;
if (isset($item['url'])) {
$item['url'] = UrlHelper::getUrl($item['url']);
} else {
$item['url'] = UrlHelper::getUrl($handle);
}
}
return $nav;
}
示例5: getSource
/**
* Gets the source code of a template.
*
* @param string $name The name of the template to load, or a StringTemplate object.
* @return string The template source code.
*/
public function getSource($name)
{
if (is_string($name)) {
return IOHelper::getFileContents(craft()->templates->findTemplate($name));
} else {
return $name->template;
}
}
示例6: getFileContents
/**
* @param $fileName
*
* @return array|bool|string
*
* @throws Exception
*/
private function getFileContents($fileName)
{
$filePath = craft()->path->getLogPath() . $fileName;
if (IOHelper::fileExists($filePath) === false) {
$message = sprintf('Requested logfile "%s" does not seem to exist', $fileName);
throw new Exception($message);
} else {
return IOHelper::getFileContents($filePath);
}
}
开发者ID:nerds-and-company,项目名称:craft-customlogviewer-plugin,代码行数:17,代码来源:Customlogviewer_CustomlogviewerController.php
示例7: getContents
/**
* Set our location based on contents of filename
*
* @return String
*/
public function getContents()
{
if ($this->_contents === null) {
$this->_contents = IOHelper::getFileContents($this->filenamePath);
if ($this->_contents === false) {
throw new Exception('Minimee could not get local asset: ' . $this->filenamePath);
}
}
return $this->_contents;
}
示例8: actionDownload
/**
* Download zip.
*/
public function actionDownload()
{
// Get wanted filename
$filename = craft()->request->getRequiredParam('filename');
// Get file id's
$files = craft()->request->getRequiredParam('files');
// Generate zipfile
$zipfile = craft()->zipAssets->download($files, $filename);
// Download it
craft()->request->sendFile(IOHelper::getFileName($zipfile), IOHelper::getFileContents($zipfile), array('forceDownload' => true));
}
示例9: getSource
/**
* Gets the source code of a template.
*
* @param string $name The name of the template to load, or a StringTemplate object.
*
* @throws Exception
* @return string The template source code.
*/
public function getSource($name)
{
if (is_string($name)) {
$template = $this->_findTemplate($name);
if (IOHelper::isReadable($template)) {
return IOHelper::getFileContents($template);
} else {
throw new Exception(Craft::t('Tried to read the template at {path}, but could not. Check the permissions.', array('path' => $template)));
}
} else {
return $name->template;
}
}
示例10: render
/**
* @param $view
* @param $data
*
* @return mixed
*/
protected function render($view, $data)
{
if (!craft()->isConsole() && !craft()->request->isResourceRequest() && !craft()->request->isAjaxRequest() && craft()->config->get('devMode') && in_array(HeaderHelper::getMimeType(), array('text/html', 'application/xhtml+xml'))) {
if (($userAgent = craft()->request->getUserAgent()) !== null && preg_match('/msie [5-9]/i', $userAgent)) {
echo '<script type="text/javascript">';
echo IOHelper::getFileContents(IOHelper::getFolderName(__FILE__) . '/../vendors/console-normalizer/normalizeconsole.min.js');
echo "</script>\n";
} else {
$viewFile = craft()->path->getCpTemplatesPath() . 'logging/' . $view . '-firebug.php';
include craft()->findLocalizedFile($viewFile, 'en');
}
}
}
示例11: restore
/**
* @param $filePath
*
* @throws Exception
*/
public function restore($filePath)
{
if (!IOHelper::fileExists($filePath)) {
throw new Exception(Craft::t('Could not find the SQL file to restore: {filePath}', array('filePath' => $filePath)));
}
$this->_nukeDb();
$sql = IOHelper::getFileContents($filePath, true);
array_walk($sql, array($this, 'trimValue'));
$sql = array_filter($sql);
$statements = $this->_buildSQLStatements($sql);
foreach ($statements as $statement) {
Craft::log('Executing SQL statement: ' . $statement);
$command = craft()->db->createCommand($statement);
$command->execute();
}
}
示例12: actionDownload
/**
* Downloads an import file.
*
* @throws HttpException If not found
*/
public function actionDownload()
{
// Get history id
$history = craft()->request->getParam('id');
// Get history
$model = Import_HistoryRecord::model()->findById($history);
// Get filepath
$path = craft()->path->getStoragePath() . 'import/' . $history . '/' . $model->file;
// Check if file exists
if (file_exists($path)) {
// Send the file to the browser
craft()->request->sendFile($model->file, IOHelper::getFileContents($path), array('forceDownload' => true));
}
// Not found, = 404
throw new HttpException(404);
}
示例13: loadImage
/**
* Loads an image from a file system path.
*
* @param string $path
*
* @throws Exception
* @return Image
*/
public function loadImage($path)
{
if (!IOHelper::fileExists($path)) {
throw new Exception(Craft::t('No file exists at the path “{path}”', array('path' => $path)));
}
list($width, $height) = ImageHelper::getImageSize($path);
$svg = IOHelper::getFileContents($path);
// If the size is defined by viewbox only, add in width and height attributes
if (!preg_match(static::SVG_WIDTH_RE, $svg) && preg_match(static::SVG_HEIGHT_RE, $svg)) {
$svg = preg_replace(static::SVG_TAG_RE, "<svg width=\"{$width}px\" height=\"{$height}px\" ", $svg);
}
$this->_height = $height;
$this->_width = $width;
$this->_svgContent = $svg;
return $this;
}
示例14: 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;
}
示例15: serveAsset
public function serveAsset(array $options = array())
{
if (isset($options['id'])) {
if (!$this->_asset or $this->_asset->id != $options['id'] or !$this->_asset instanceof AssetFileModel) {
$this->_asset = craft()->assets->getFileById($options['id']);
if (!$this->_asset) {
throw new Exception(Craft::t("Unable to find asset"));
}
}
$sendFile = false;
if ($this->_asset->source->type == 'Local') {
$sourcePath = $this->_asset->source->sourceType->getBasePath();
$folderPath = $this->_asset->getFolder()->path;
$path = $sourcePath . $folderPath . $this->_asset->filename;
if (IOHelper::fileExists($path)) {
$content = IOHelper::getFileContents($path);
$sendFile = true;
}
} else {
$path = $this->_asset->url;
$client = new \Guzzle\Http\Client();
$response = $client->get($this->_asset->url)->send();
if ($response->isSuccessful()) {
$content = $response->getBody();
$sendFile = true;
}
}
if ($sendFile) {
if (isset($options['forceDownload']) and !$options['forceDownload']) {
$extraParams = array('forceDownload' => false);
} else {
$extraParams = array('forceDownload' => true);
}
craft()->request->sendFile($path, $content, $extraParams);
} else {
throw new Exception(Craft::t("Unable to serve file"));
}
}
}