本文整理汇总了PHP中Filesystem::extension方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::extension方法的具体用法?PHP Filesystem::extension怎么用?PHP Filesystem::extension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Filesystem
的用法示例。
在下文中一共展示了Filesystem::extension方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: filename
protected function filename($filename)
{
if (is_null(Filesystem::extension($filename))) {
$filename .= '.htm';
}
return $filename . '.php';
}
示例2: extension
public function extension($file, $ext)
{
if (strpos($file, '?') === false && Filesystem::extension($file) != $ext) {
$file .= '.' . $ext;
}
return $file;
}
示例3: getStaticProperUrl
/**
* Return URL with fingerprint
* @param type $sRootPath Path from root
*/
public static function getStaticProperUrl($sRootPath)
{
$sFilePath = Filesystem::path($sRootPath);
$sFileName = Filesystem::name($sRootPath);
$sFileExtension = Filesystem::extension($sRootPath);
$sFileLastModificationDate = filemtime($sRootPath);
$sUrl = Config::get('app.url') . $sFilePath . Config::get('format.dir.slash') . $sFileName . '_' . $sFileLastModificationDate . '_.' . $sFileExtension;
return $sUrl;
}
示例4: migrate
function migrate($migration, $connection)
{
echo 'importing ' . $migration . '... ';
$ext = Filesystem::extension($migration);
if ($ext == 'php') {
require_once 'db/migrations/' . $migration;
$classname = get_migration_name($migration);
$classname::migrate($connection);
} else {
$connection->query(utf8_decode(Filesystem::read('db/migrations/' . $migration)));
}
$connection->create(array('table' => 'schema_migrations', 'values' => array('version' => get_migration_version($migration))));
echo 'done' . PHP_EOL;
}
示例5: populateState
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @since 1.6
*/
protected function populateState()
{
// Load the User state.
$id = User::getState('com_templates.edit.source.id');
// Parse the template id out of the compound reference.
$temp = explode(':', base64_decode($id));
$this->setState('extension.id', (int) array_shift($temp));
$fileName = array_shift($temp);
$this->setState('filename', $fileName);
// Save the syntax for later use
User::setState('editor.source.syntax', Filesystem::extension($fileName));
// Load the parameters.
$params = Component::params('com_templates');
$this->setState('params', $params);
}
示例6: canUpload
/**
* Checks if the file can be uploaded
* @param array File information
* @param string An error message to be returned
* @return boolean
*/
function canUpload($file, &$err)
{
$params = Component::params('com_media');
$format = Filesystem::extension($file['name']);
$allowable = explode(',', $params->get('upload_extensions'));
if (!in_array($format, $allowable)) {
$err = Lang::txt('COM_MEDIA_ERROR_WARNFILETYPE');
return false;
}
$maxSize = (int) ($params->get('upload_maxsize', 0) * 1024 * 1024);
if ($maxSize > 0 && (int) $file['size'] > $maxSize) {
$err = Lang::txt('COM_MEDIA_ERROR_WARNFILETOOLARGE');
return false;
}
return true;
}
示例7: productimage
/**
* Get a default image for the store item
*
* @param string $option Component name
* @param string $item Item ID
* @param string $root Root path
* @param string $wpath Base path for files
* @param string $alt Image alt text
* @param string $category Item category
* @return string HTML
*/
public static function productimage($option, $item, $root, $wpath, $alt, $category)
{
if ($wpath) {
$wpath = DS . trim($wpath, DS) . DS;
}
$d = @dir($root . $wpath . $item);
$images = array();
$html = '';
if ($d) {
while (false !== ($entry = $d->read())) {
$img_file = $entry;
if (is_file($root . $wpath . $item . DS . $img_file) && substr($entry, 0, 1) != '.' && strtolower($entry) !== 'index.html') {
if (preg_match("#bmp|gif|jpg|png|swf#i", $img_file)) {
$images[] = $img_file;
}
}
}
$d->close();
} else {
if ($category == 'service') {
$html = '<span class="nophoto"></span>';
} else {
$html = '<span class="nophoto premium"></span>';
}
}
sort($images);
$els = '';
$k = 0;
$g = 0;
for ($i = 0, $n = count($images); $i < $n; $i++) {
$ext = \Filesystem::extension($images[$i]);
$tn = \Filesystem::name($images[$i]) . '-tn.';
if (!is_file($root . $wpath . $item . DS . $tn . $ext)) {
$ext = 'gif';
}
$tn = $tn . $ext;
if (is_file($root . $wpath . $item . DS . $tn)) {
$k++;
$els .= '<a rel="lightbox" href="' . $wpath . $item . '/' . $images[$i] . '" title="' . $alt . '"><img src="' . $wpath . $item . '/' . $tn . '" alt="' . $alt . '" /></a>';
}
}
if ($els) {
$html .= $els;
}
return $html;
}
示例8: validates
public function validates($file)
{
$this->errors = array();
if (empty($file) && !isset($file['name'])) {
return $this->error('InvalidParam');
}
if ($this->maxSize && filesize($file['tmp_name']) > $this->maxSize * 1024 * 1024) {
return $this->error('FileSizeExceeded');
}
$ext = Filesystem::extension($file['name']);
if (!empty($this->allowedTypes) && !in_array($ext, $this->allowedTypes)) {
return $this->error('FileTypeNotAllowed');
}
if ($uploadError = $this->uploadError($file['error'])) {
return $this->error($uploadError);
}
return true;
}
示例9: loadConfig
/**
* loadConfig
*
* @param string $name
* @access public
* @return void
*/
public function loadConfig($name = '')
{
$baseDir = PATH_APP . DS . 'config' . DS . 'search' . DS . 'types';
if ($name == '') {
$configFiles = Filesystem::listContents($baseDir);
$config = array();
foreach ($configFiles as $file) {
if (Filesystem::extension($baseDir . $file['path']) == 'php') {
$typeConfig = (require_once $baseDir . $file['path']);
array_push($config, $typeConfig);
}
}
return $config;
} elseif ($name != '') {
$filename = $baseDir . DS . $name . '.php';
if (Filesystem::exists($filename)) {
$config = (include $filename);
} else {
$config = false;
}
return $config;
}
return false;
}
示例10: elseif
<div id="transcript-container">
<div id="transcript-toolbar">
<div id="transcript-select"></div>
<input type="text" id="transcript-search" placeholder="Search Transcript..." />
<a href="javascript:void(0);" id="font-bigger"></a>
<a href="javascript:void(0);" id="font-smaller"></a>
</div>
<div id="transcripts"></div>
</div>
</div>
<?php
} elseif ($type == 'standalone') {
?>
<?php
$path = DS . trim(substr(PATH_APP, strlen(PATH_ROOT)), DS) . DS . ltrim($path . DS . $this->model->get('url'), DS);
$ext = strtolower(Filesystem::extension(PATH_ROOT . $path));
Document::addStyleSheet('//releases.flowplayer.org/5.4.2/skin/minimalist.css');
Document::addScript('//releases.flowplayer.org/5.4.2/flowplayer.min.js');
?>
<div class="flowplayer">
<video id="movie<?php
echo rand(0, 1000);
?>
" preload controls>
<?php
switch ($ext) {
case 'mov':
case 'mp4':
case 'm4v':
echo '<source src="' . $path . '" type="video/mp4" />';
break;
示例11: upload
/**
* Uploads a file to a given directory and returns an attachment string
* that is appended to report/comment bodies
*
* @param string $listdir Directory to upload files to
* @return string A string that gets appended to messages
*/
public function upload($listdir, $post_id)
{
// Check if they are logged in
if (User::isGuest()) {
return;
}
if (!$listdir) {
$this->setError(Lang::txt('PLG_GROUPS_FORUM_NO_UPLOAD_DIRECTORY'));
return;
}
// Incoming file
$file = Request::getVar('upload', '', 'files', 'array');
if (!$file['name']) {
return;
}
// Incoming
$description = trim(Request::getVar('description', ''));
// Construct our file path
$path = PATH_APP . DS . trim($this->params->get('filepath', '/site/forum'), DS) . DS . $listdir;
if ($post_id) {
$path .= DS . $post_id;
}
// Build the path if it doesn't exist
if (!is_dir($path)) {
if (!Filesystem::makeDirectory($path)) {
$this->setError(Lang::txt('PLG_GROUPS_FORUM_UNABLE_TO_CREATE_UPLOAD_PATH'));
return;
}
}
// Make the filename safe
$file['name'] = Filesystem::clean($file['name']);
$file['name'] = str_replace(' ', '_', $file['name']);
$ext = strtolower(Filesystem::extension($file['name']));
// Perform the upload
if (!Filesystem::upload($file['tmp_name'], $path . DS . $file['name'])) {
$this->setError(Lang::txt('PLG_GROUPS_FORUM_ERROR_UPLOADING'));
return;
} else {
// File was uploaded
// Create database entry
$row = new \Components\Forum\Tables\Attachment($this->database);
$row->bind(array('id' => 0, 'parent' => $listdir, 'post_id' => $post_id, 'filename' => $file['name'], 'description' => $description));
if (!$row->check()) {
$this->setError($row->getError());
}
if (!$row->store()) {
$this->setError($row->getError());
}
}
}
示例12: editTask
/**
* Edit Newsletter Story Task
*
* @return void
*/
public function editTask()
{
//get request vars
$this->view->type = strtolower(Request::getVar("type", "primary"));
$this->view->id = Request::getInt("id", 0);
$this->view->sid = Request::getInt("sid", 0);
//load campaign
$this->view->newsletter = new Newsletter($this->database);
$this->view->newsletter->load($this->view->id);
//default object
$this->view->story = new stdClass();
$this->view->story->id = null;
$this->view->story->order = null;
$this->view->story->title = null;
$this->view->story->story = null;
$this->view->story->readmore_title = null;
$this->view->story->readmore_link = null;
//are we editing
if ($this->view->sid) {
if ($this->view->type == "primary") {
$this->view->story = new PrimaryStory($this->database);
} else {
$this->view->story = new SecondaryStory($this->database);
}
$this->view->story->load($this->view->sid);
}
// Set any errors
if ($this->getError()) {
$this->view->setError($this->getError());
}
// If we are creating an auto-generated newsletter
if ($this->view->type == 'autogen') {
// Load available sources
$this->view->enabledSources = Event::trigger('newsletter.onGetEnabledDigests');
/* It should be noted that these are not served via the CMS, per se. Rather they
* JavaScript will manipulate the DOM and save the HTML as a string into the Primary
* Story content field.
*/
// The path where the Story Template Layouts are.
$viewPath = dirname(__DIR__) . DS . 'views' . DS . 'storytemplates' . DS . 'tmpl';
// Get available layouts
$contents = Filesystem::listContents($viewPath);
// Empty bucket to hold layout names;
$this->view->layouts = array();
// Make sure we aren't including any cruft.
foreach ($contents as $file) {
// Check for php extention
if (Filesystem::extension($viewPath . DS . $file['path']) == 'php' && $file['path'] != '/index.php') {
// Some trimming of the leading / and the .php; push into bucket
array_push($this->view->layouts, rtrim(ltrim($file['path'], "//"), ".php"));
}
}
// Display the alternative layout
$this->view->setLayout('_autogen')->display();
} else {
// Output the HTML
$this->view->setLayout('edit')->display();
}
}
示例13: array
$base = $this->model->params->get('uploadpath');
$i = 0;
$xgroups = \Hubzero\User\Helper::getGroups(User::get('id'), 'all');
$usersgroups = array();
if (!empty($xgroups)) {
foreach ($xgroups as $group) {
if ($group->regconfirmed) {
$usersgroups[] = $group->cn;
}
}
}
$allowedgroups = $this->model->resource->getGroups();
foreach ($children as $child) {
if ($child->access == 0 || $child->access == 1 && !User::isGuest() || $child->access == 3 && in_array($this->model->resource->group_owner, $usersgroups)) {
$i++;
$ftype = Filesystem::extension($child->path);
if (substr($child->path, 0, 4) == 'http') {
$ftype = 'html';
}
$class = '';
$action = '';
if ($child->standalone == 1) {
$liclass = ' class="html"';
$title = stripslashes($child->title);
} else {
$rt = \Components\Resources\Tables\Type::getRecordInstance($child->type);
$tparams = new \Hubzero\Config\Registry($rt->params);
$lt = \Components\Resources\Tables\Type::getRecordInstance($child->logicaltype);
$ltparams = new \Hubzero\Config\Registry($lt->params);
// Check the link action by child's type
if ($child->logicaltype) {
示例14: _embed
/**
* Generates HTML to either embed a file or link to file for download
*
* @param string $file File to embed
* @param array $attr Attributes to apply to the HTML
* @return string
*/
private function _embed($file, $attr = array())
{
$ext = strtolower(Filesystem::extension($file));
switch ($ext) {
case 'unity3d':
$attr['width'] = isset($attr['width']) && $attr['width'] ? $attr['width'] : 400;
$attr['height'] = isset($attr['height']) && $attr['height'] ? $attr['height'] : 400;
if (isset($attr['style']['width'])) {
$attr['width'] = intval($attr['style']['width']);
}
if (isset($attr['style']['height'])) {
$attr['height'] = intval($attr['style']['height']);
}
$attr['href'] = isset($attr['href']) && $attr['href'] && $attr['href'] != 'none' ? $attr['href'] : $this->_link($file);
/*if (!array_key_exists('alt', $attr)
&& array_key_exists('altimage', $attr)
&& $attr['altimage'] != ''
&& file_exists($this->_path($attr['altimage'])))
{
//$attr['href'] = (array_key_exists('althref', $attr) && $attr['althref'] != '') ? $attr['althref'] : $attr['href'];
$althref = (array_key_exists('althref', $attr) && $attr['althref'] != '') ? $attr['althref'] : $attr['href'];
$attr['alt'] = '<a class="attachment" rel="internal" href="' . $althref . '" title="' . htmlentities($attr['desc'], ENT_COMPAT, 'UTF-8') . '">';
$attr['alt'] .= '<img src="' . $this->_link($attr['altimage']) . '" alt="' . htmlentities($attr['desc'], ENT_COMPAT, 'UTF-8') . '" />';
$attr['alt'] .= '</a>';
}
else
{
$althref = (array_key_exists('althref', $attr) && $attr['althref'] != '') ? $attr['althref'] : $attr['href'];
$attr['alt'] = (isset($attr['alt'])) ? $attr['alt'] : '';
$attr['alt'] .= '<a class="attachment" rel="internal" href="' . $althref . '" title="' . htmlentities($attr['desc'], ENT_COMPAT, 'UTF-8') . '">' . $attr['desc'] . '</a>';
}*/
$rand = rand(0, 100000);
$html = '<script type="text/javascript" src="' . (\Request::scheme() == 'https' ? 'https://ssl-' : 'http://') . 'webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/UnityObject2.js"></script>' . "\n";
$html .= '<div id="unityPlayer' . $rand . '">
<div class="missing">
<a href="http://unity3d.com/webplayer/" title="Unity Web Player. Install now!">
<img alt="Unity Web Player. Install now!" src="' . (\Request::scheme() == 'https' ? 'https://ssl-' : 'http://') . 'webplayer.unity3d.com/installation/getunity.png" width="193" height="63" />
</a>
</div>
</div>' . "\n";
$html .= '<script type="text/javascript">' . "\n";
$html .= '<!--
var config = {
width: ' . intval($attr['width']) . ',
height: ' . intval($attr['height']) . ',
params: { enableDebugging:"0" }
}
var u = new UnityObject2(config);
var unityObject = $("#unityPlayer' . $rand . '");
u.initPlugin(unityObject, "' . $attr['href'] . '");
-->' . "\n";
$html .= '</script>' . "\n";
break;
case 'cdf':
$attr['width'] = isset($attr['width']) && $attr['width'] ? $attr['width'] : 400;
$attr['height'] = isset($attr['height']) && $attr['height'] ? $attr['height'] : 400;
if (isset($attr['style']['width'])) {
$attr['width'] = intval($attr['style']['width']);
}
if (isset($attr['style']['height'])) {
$attr['height'] = intval($attr['style']['height']);
}
$attr['href'] = isset($attr['href']) && $attr['href'] && $attr['href'] != 'none' ? $attr['href'] : $this->_link($file);
$rand = rand(0, 100000);
if (!array_key_exists('alt', $attr) && array_key_exists('altimage', $attr) && $attr['altimage'] != '' && file_exists($this->_path($attr['altimage']))) {
//$attr['href'] = (array_key_exists('althref', $attr) && $attr['althref'] != '') ? $attr['althref'] : $attr['href'];
$althref = array_key_exists('althref', $attr) && $attr['althref'] != '' ? $attr['althref'] : $attr['href'];
$attr['alt'] = '<a href="http://www.wolfram.com/cdf-player/" title="CDF Web Player. Install now!">';
$attr['alt'] .= '<img src="' . $this->_link($attr['altimage']) . '" alt="' . htmlentities($attr['desc'], ENT_COMPAT, 'UTF-8') . '" />';
$attr['alt'] .= '</a>';
} else {
$attr['alt'] = '<div class="embedded-plugin" style="width: ' . intval($attr['width']) . 'px; height: ' . intval($attr['height']) . 'px;"><a class="missing-plugin" href="http://www.wolfram.com/cdf-player/" title="CDF Web Player. Install now!"><img alt="CDF Web Player. Install now!" src="' . $juri->getScheme() . '://www.wolfram.com/cdf/images/cdf-player-black.png" width="187" height="41" /></a></div>';
}
$html = '<script type="text/javascript" src="' . \Request::scheme() . '://www.wolfram.com/cdf-player/plugin/v2.1/cdfplugin.js"></script>';
$html .= '<script type="text/javascript">';
//$html .= '<!--';
$html .= ' var cdf = new cdfplugin();';
$html .= "var defaultContent = '" . $attr['alt'] . "';";
$html .= ' if (defaultContent!= "") {';
$html .= ' cdf.setDefaultContent(defaultContent);';
$html .= ' }';
$html .= ' cdf.embed(\'' . $attr['href'] . '\', ' . intval($attr['width']) . ', ' . intval($attr['height']) . ');';
//$html .= ' -->';
$html .= '</script>' . "\n";
$html .= '<noscript>';
$html .= '<div class="embedded-plugin" style="width: ' . intval($attr['width']) . 'px; height: ' . intval($attr['height']) . ';">';
$html .= $attr['alt'];
$html .= '</div>';
$html .= '</noscript>' . "\n";
break;
default:
$attr['alt'] = isset($attr['alt']) ? htmlentities($attr['alt'], ENT_COMPAT, 'UTF-8') : $attr['desc'];
if (!$attr['alt']) {
//.........这里部分代码省略.........
示例15: saveTask
/**
* Save an Import
*
* @return void
*/
public function saveTask()
{
// check token
Session::checkToken();
// get request vars
$import = Request::getVar('import', array());
$hooks = Request::getVar('hooks', array());
$params = Request::getVar('params', array());
$file = Request::getVar('file', array(), 'FILES');
// create import model object
$this->import = new Models\Import();
// set our hooks
$this->import->set('hooks', json_encode($hooks));
// load current params
$iparams = new \Hubzero\Config\Registry($this->import->get('params'));
// bind incoming params
$iparams->parse($params);
// set params on import object
$this->import->set('params', $iparams->toString());
// bind input to model
if (!$this->import->bind($import)) {
$this->setError($this->import->getError());
return $this->editTask();
}
// is this a new import
$isNew = false;
if (!$this->import->get('id')) {
$isNew = true;
// set the created by/at
$this->import->set('created_by', User::get('id'));
$this->import->set('created_at', Date::toSql());
}
// do we have a data file
if ($this->import->get('file')) {
// get record count
$importImporter = new Importer();
$count = $importImporter->count($this->import);
$this->import->set('count', $count);
}
// attempt to save
if (!$this->import->store(true)) {
$this->setError($this->import->getError());
return $this->editTask();
}
// is this a new import
if ($isNew) {
// create folder for files
$this->_createImportFilespace($this->import);
}
// if we have a file
if (is_array($file) && $file['size'] > 0 && $file['error'] == 0) {
$ext = strtolower(Filesystem::extension($file['name']));
if (!in_array($ext, array('csv', 'xml'))) {
$this->setError(Lang::txt('COM_RESOURCES_IMPORT_UNSUPPORTED_FILE_TYPE'));
return $this->editTask();
}
if (!is_dir($this->import->fileSpacePath())) {
Filesystem::makeDirectory($this->import->fileSpacePath());
}
move_uploaded_file($file['tmp_name'], $this->import->fileSpacePath() . DS . $file['name']);
$this->import->set('file', $file['name']);
}
// do we have a data file
if ($this->import->get('file')) {
// get record count
$importImporter = new Importer();
$count = $importImporter->count($this->import);
$this->import->set('count', $count);
}
// save again with import count
if (!$this->import->store(true)) {
$this->setError($this->import->getError());
return $this->editTask();
}
//inform user & redirect
App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=display', false), Lang::txt('COM_RESOURCES_IMPORT_CREATED'), 'passed');
}