本文整理汇总了PHP中General::getExtension方法的典型用法代码示例。如果您正苦于以下问题:PHP General::getExtension方法的具体用法?PHP General::getExtension怎么用?PHP General::getExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类General
的用法示例。
在下文中一共展示了General::getExtension方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __get
public function __get($name)
{
if ($name == "extension") {
return "." . General::getExtension($this->file);
}
if ($name == "mimetype") {
return mime_content_type($this->location);
}
if ($name == "size") {
return $this->file->getSize();
}
if ($name == "rawname") {
return $this->file->getFilename();
}
if ($name == "errors") {
return $this->errors;
}
return $this->{$name};
}
示例2: __sniffMIMEType
private static function __sniffMIMEType($file)
{
$imageMimeTypes = array('image/gif', 'image/jpg', 'image/jpeg', 'image/png');
if (in_array('image/' . General::getExtension($file), $imageMimeTypes)) {
return 'image/' . General::getExtension($file);
}
return 'unknown';
}
示例3: processRawFieldData
public function processRawFieldData($data, &$status, &$message = null, $simulate = false, $entry_id = null)
{
$status = self::__OK__;
// No file given, save empty data:
if ($data === null) {
return array('file' => null, 'mimetype' => null, 'size' => null, 'meta' => null);
}
// Its not an array, so just retain the current data and return:
if (is_array($data) === false) {
$file = $this->getFilePath(basename($data));
$result = array('file' => $data, 'mimetype' => null, 'size' => null, 'meta' => null);
// Grab the existing entry data to preserve the MIME type and size information
if (isset($entry_id)) {
$row = Symphony::Database()->fetchRow(0, sprintf("SELECT `file`, `mimetype`, `size`, `meta` FROM `tbl_entries_data_%d` WHERE `entry_id` = %d", $this->get('id'), $entry_id));
if (empty($row) === false) {
$result = $row;
}
}
// Found the file, add any missing meta information:
if (file_exists($file) && is_readable($file)) {
if (empty($result['mimetype'])) {
$result['mimetype'] = General::getMimeType($file);
}
if (empty($result['size'])) {
$result['size'] = filesize($file);
}
if (empty($result['meta'])) {
$result['meta'] = serialize(self::getMetaInfo($file, $result['mimetype']));
}
// The file was not found, or is unreadable:
} else {
$message = __('The file uploaded is no longer available. Please check that it exists, and is readable.');
$status = self::__INVALID_FIELDS__;
}
return $result;
}
if ($simulate && is_null($entry_id)) {
return $data;
}
// Check to see if the entry already has a file associated with it:
if (is_null($entry_id) === false) {
$row = Symphony::Database()->fetchRow(0, sprintf("SELECT *\n FROM `tbl_entries_data_%s`\n WHERE `entry_id` = %d\n LIMIT 1", $this->get('id'), $entry_id));
$existing_file = isset($row['file']) ? $this->getFilePath($row['file']) : null;
// File was removed:
if ($data['error'] == UPLOAD_ERR_NO_FILE && !is_null($existing_file) && is_file($existing_file)) {
General::deleteFile($existing_file);
}
}
// Do not continue on upload error:
if ($data['error'] == UPLOAD_ERR_NO_FILE || $data['error'] != UPLOAD_ERR_OK) {
return false;
}
// Where to upload the new file?
$abs_path = DOCROOT . '/' . trim($this->get('destination'), '/');
$rel_path = str_replace('/workspace', '', $this->get('destination'));
// Sanitize the filename
$data['name'] = Lang::createFilename($data['name']);
// If a file already exists, then rename the file being uploaded by
// adding `_1` to the filename. If `_1` already exists, the logic
// will keep adding 1 until a filename is available (#672)
if (file_exists($abs_path . '/' . $data['name'])) {
$extension = General::getExtension($data['name']);
$new_file = substr($abs_path . '/' . $data['name'], 0, -1 - strlen($extension));
$renamed_file = $new_file;
$count = 1;
do {
$renamed_file = $new_file . '_' . $count . '.' . $extension;
$count++;
} while (file_exists($renamed_file));
// Extract the name filename from `$renamed_file`.
$data['name'] = str_replace($abs_path . '/', '', $renamed_file);
}
$file = $this->getFilePath($data['name']);
// Attempt to upload the file:
$uploaded = General::uploadFile($abs_path, $data['name'], $data['tmp_name'], Symphony::Configuration()->get('write_mode', 'file'));
if ($uploaded === false) {
$message = __('There was an error while trying to upload the file %1$s to the target directory %2$s.', array('<code>' . $data['name'] . '</code>', '<code>workspace/' . ltrim($rel_path, '/') . '</code>'));
$status = self::__ERROR_CUSTOM__;
return false;
}
// File has been replaced:
if (isset($existing_file) && $existing_file !== $file && is_file($existing_file)) {
General::deleteFile($existing_file);
}
// Get the mimetype, don't trust the browser. RE: #1609
$data['type'] = General::getMimeType($file);
return array('file' => basename($file), 'size' => $data['size'], 'mimetype' => $data['type'], 'meta' => serialize(self::getMetaInfo($file, $data['type'])));
}
示例4: run
public function run()
{
// Initialize log
if (is_null(Symphony::Log())) {
self::__render(new UpdaterPage('missing-log'));
}
// Get available migrations. This will only contain the migrations
// that are applicable to the current install.
$migrations = array();
foreach (new DirectoryIterator(INSTALL . '/migrations') as $m) {
if ($m->isDot() || $m->isDir() || General::getExtension($m->getFilename()) !== 'php') {
continue;
}
$version = str_replace('.php', '', $m->getFilename());
// Include migration so we can see what the version is
include_once $m->getPathname();
$classname = 'migration_' . str_replace('.', '', $version);
$m = new $classname();
if (version_compare(Symphony::Configuration()->get('version', 'symphony'), call_user_func(array($m, 'getVersion')), '<')) {
$migrations[call_user_func(array($m, 'getVersion'))] = $m;
}
}
// The DirectoryIterator may return files in a sporatic order
// on different servers. This will ensure the array is sorted
// correctly using `version_compare`
uksort($migrations, 'version_compare');
// If there are no applicable migrations then this is up to date
if (empty($migrations)) {
Symphony::Log()->pushToLog(sprintf('Updater - Already up-to-date'), E_ERROR, true);
self::__render(new UpdaterPage('uptodate'));
} else {
if (!isset($_POST['action']['update'])) {
$notes = array();
// Loop over all available migrations showing there
// pre update notes.
foreach ($migrations as $version => $m) {
$n = call_user_func(array($m, 'preUpdateNotes'));
if (!empty($n)) {
$notes[$version] = $n;
}
}
// Show the update ready page, which will display the
// version and release notes of the most recent migration
self::__render(new UpdaterPage('ready', array('pre-notes' => $notes, 'version' => call_user_func(array($m, 'getVersion')), 'release-notes' => call_user_func(array($m, 'getReleaseNotes')))));
} else {
$notes = array();
$canProceed = true;
// Loop over all the available migrations incrementally applying
// the upgrades. If any upgrade throws an uncaught exception or
// returns false, this will break and the failure page shown
foreach ($migrations as $version => $m) {
$n = call_user_func(array($m, 'postUpdateNotes'));
if (!empty($n)) {
$notes[$version] = $n;
}
$canProceed = call_user_func(array($m, 'run'), 'upgrade', Symphony::Configuration()->get('version', 'symphony'));
Symphony::Log()->pushToLog(sprintf('Updater - Migration to %s was %s', $version, $canProceed ? 'successful' : 'unsuccessful'), E_NOTICE, true);
if (!$canProceed) {
break;
}
}
if (!$canProceed) {
self::__render(new UpdaterPage('failure'));
} else {
self::__render(new UpdaterPage('success', array('post-notes' => $notes, 'version' => call_user_func(array($m, 'getVersion')), 'release-notes' => call_user_func(array($m, 'getReleaseNotes')))));
}
}
}
}
示例5: getMimeType
public function getMimeType($file)
{
if (in_array('image/' . General::getExtension($file), $this->_mimes['image'])) {
return 'image/' . General::getExtension($file);
}
return 'application/octet-stream';
}
示例6: __sniffMIMEType
private static function __sniffMIMEType($file)
{
$ext = strtolower(General::getExtension($file));
$imageMimeTypes = array('image/gif', 'image/jpg', 'image/jpeg', 'image/png');
if (General::in_iarray("image/{$ext}", $imageMimeTypes)) {
return "image/{$ext}";
}
return 'unknown';
}
示例7: listStructureFlat
function listStructureFlat($dir = ".", $filters = array(), $recurse = true, $sort = "asc", $strip_root = NULL, $exclude = array(), $ignore_hidden = true)
{
$files = array();
if (!($handle = @opendir($dir))) {
return array();
}
while (($file = @readdir($handle)) != false) {
if ($file != '.' && $file != '..' && (!$ignore_hidden || $ignore_hidden && $file[0] != '.')) {
if (@is_dir("{$dir}/{$file}")) {
if ($recurse) {
$files = array_merge($files, General::listStructureFlat("{$dir}/{$file}", $filters, $recurse, $sort, $strip_root, $exclude, $ignore_hidden));
}
} else {
$can_include = true;
if (!empty($filters)) {
$can_include = in_array(General::getExtension($file), $filters);
}
if (!empty($exclude)) {
$can_include = !in_array(General::getExtension($file), $exclude);
}
if ($can_include) {
$files[] = array("name" => $file, "path" => $dir);
}
}
}
}
@closedir($handle);
if ($sort == 'desc') {
usort($files, array('General', 'fileSortR'));
} elseif ($sort == 'mtime') {
usort($files, array('General', 'filemtimeSort'));
} else {
usort($files, array('General', 'fileSort'));
}
if ($strip_root) {
for ($ii = 0; $ii < count($files); $ii++) {
$files[$ii]['path'] = str_replace($strip_root, "", $files[$ii]['path']);
}
}
return $files;
}
示例8: processRawFieldData
public function processRawFieldData($data, &$status, &$message = null, $simulate = false, $entry_id = NULL)
{
$status = self::__OK__;
//fixes bug where files are deleted, but their database entries are not.
if ($data === NULL) {
return array('file' => NULL, 'mimetype' => NULL, 'size' => NULL, 'meta' => NULL);
}
// It's not an array, so just retain the current data and return
if (!is_array($data)) {
// Ensure the file exists in the `WORKSPACE` directory
// @link http://symphony-cms.com/discuss/issues/view/610/
$file = WORKSPACE . preg_replace(array('%/+%', '%(^|/)\\.\\./%'), '/', $data);
$result = array('file' => $data, 'mimetype' => NULL, 'size' => NULL, 'meta' => NULL);
// Grab the existing entry data to preserve the MIME type and size information
if (isset($entry_id) && !is_null($entry_id)) {
$row = Symphony::Database()->fetchRow(0, sprintf("SELECT `file`, `mimetype`, `size`, `meta` FROM `tbl_entries_data_%d` WHERE `entry_id` = %d", $this->get('id'), $entry_id));
if (!empty($row)) {
$result = $row;
}
}
if (!file_exists($file) || !is_readable($file)) {
$message = __('The file uploaded is no longer available. Please check that it exists, and is readable.');
$status = self::__INVALID_FIELDS__;
return $result;
} else {
if (empty($result['mimetype'])) {
$result['mimetype'] = function_exists('mime_content_type') ? mime_content_type($file) : 'application/octet-stream';
}
if (empty($result['size'])) {
$result['size'] = filesize($file);
}
if (empty($result['meta'])) {
$result['meta'] = serialize(self::getMetaInfo($file, $result['mimetype']));
}
}
return $result;
}
if ($simulate && is_null($entry_id)) {
return $data;
}
//My special Select box alteration :P
//var_dump($_POST['fields']['enhanced_upload_field'][$this->get('element_name')]['directory'],$_POST);die;
//var_dump($_POST);
// Upload the new file
$override_path = $this->get('override') == 'yes' ? $_POST['fields']['enhanced_upload_field'][$this->get('element_name')]['directory'] : trim($this->get('destination'));
$abs_path = DOCROOT . $override_path . '/';
$rel_path = str_replace('/workspace', '', $override_path);
$existing_file = NULL;
if (!is_null($entry_id)) {
$row = Symphony::Database()->fetchRow(0, sprintf("SELECT * FROM `tbl_entries_data_%s` WHERE `entry_id` = %d LIMIT 1", $this->get('id'), $entry_id));
$existing_file = '/' . trim($row['file'], '/');
// File was removed
if ($data['error'] == UPLOAD_ERR_NO_FILE && !is_null($existing_file) && is_file(WORKSPACE . $existing_file)) {
General::deleteFile(WORKSPACE . $existing_file);
}
}
if ($data['error'] == UPLOAD_ERR_NO_FILE || $data['error'] != UPLOAD_ERR_OK) {
return false;
}
// If a file already exists, then rename the file being uploaded by
// adding `_1` to the filename. If `_1` already exists, the logic
// will keep adding 1 until a filename is available (#672)
$new_file = $abs_path . '/' . $data['name'];
if (file_exists($new_file)) {
$i = 1;
$extension = General::getExtension($data['name']);
$renamed_file = $new_file;
do {
$renamed_file = General::left($new_file, -strlen($extension) - 1) . '_' . $i . '.' . $extension;
$i++;
} while (file_exists($renamed_file));
// Extract the name filename from `$renamed_file`.
$data['name'] = str_replace($abs_path . '/', '', $renamed_file);
}
// Sanitize the filename
$data['name'] = Lang::createFilename($data['name']);
// Actually upload the file, moving it from PHP's temporary store to the desired destination
if (!General::uploadFile($abs_path, $data['name'], $data['tmp_name'], Symphony::Configuration()->get('write_mode', 'file'))) {
$message = __('There was an error while trying to upload the file %1$s to the target directory %2$s.', array('<code>' . $data['name'] . '</code>', '<code>workspace/' . ltrim($rel_path, '/') . '</code>'));
$status = self::__ERROR_CUSTOM__;
return false;
}
$file = rtrim($rel_path, '/') . '/' . trim($data['name'], '/');
// File has been replaced
if (!is_null($existing_file) && strtolower($existing_file) != strtolower($file) && is_file(WORKSPACE . $existing_file)) {
General::deleteFile(WORKSPACE . $existing_file);
}
// If browser doesn't send MIME type (e.g. .flv in Safari)
if (strlen(trim($data['type'])) == 0) {
$data['type'] = function_exists('mime_content_type') ? mime_content_type($file) : 'application/octet-stream';
}
//var_dump($_POST);
return array('file' => $file, 'size' => $data['size'], 'mimetype' => $data['type'], 'meta' => serialize(self::getMetaInfo(WORKSPACE . $file, $data['type'])));
}
示例9: basename
/***
*
* Symphony web publishing system
*
* Copyright 2004–2006 Twenty One Degrees Pty. Ltd.
*
* @version 1.7
* @licence https://github.com/symphonycms/symphony-1.7/blob/master/LICENCE
*
***/
if (!@is_file(WORKSPACE . $_REQUEST['file'])) {
General::redirect(URL . "/symphony/?page=/blueprint/assets/new/");
}
$Admin->addScriptToHead('assets/editor.js');
$type = General::getExtension($_REQUEST['file']);
$GLOBALS['pageTitle'] = 'Assets > ' . basename($_REQUEST['file']);
$fields = General::getFileMeta(WORKSPACE . $_REQUEST['file']);
$fields["name"] = basename($_REQUEST['file']);
$ignore = array("events", "data-sources", "text-formatters", "pages", "masters", "utilities");
$fields["location"] = "/workspace" . dirname($_REQUEST['file']) . "/";
$fields["type"] = $type;
$fields["body"] = @file_get_contents(WORKSPACE . $_REQUEST['file']);
if (defined("__SYM_ENTRY_MISSINGFIELDS__")) {
$Admin->pageAlert("required", array(@implode(", ", $required)), false, 'error');
}
$date = $Admin->getDateObj();
if (isset($_GET['_f'])) {
switch ($_GET['_f']) {
case "saved":
$Admin->pageAlert("saved-time", array("Asset", date("h:i:sa", $date->get(true, false))));
示例10: appendFormattedElement
public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = false, $mode = null, $entry_id = null)
{
$data = $this->buildFileItems($data);
$field = new XMLElement($this->get('element_name'));
foreach ($data as $file_item) {
// It is possible an array of NULL data will be passed in. Check for this.
if (!is_array($file_item) || !isset($file_item['file']) || is_null($file_item['file'])) {
return;
}
$file = $this->getFilePath(basename($file_item['file']));
$item = new XMLElement('file');
$item->setAttributeArray(array('size' => file_exists($file) && is_readable($file) ? General::formatFilesize(filesize($file)) : 'unknown', 'path' => General::sanitize(str_replace(WORKSPACE, NULL, dirname($file))), 'type' => $file_item['mimetype'], 'extension' => General::getExtension($file)));
$item->appendChild(new XMLElement('filename', General::sanitize(basename($file))));
$m = unserialize($file_item['meta']);
if (is_array($m) && !empty($m)) {
$item->appendChild(new XMLElement('meta', NULL, $m));
}
$field->appendChild($item);
}
$wrapper->appendChild($field);
return $wrapper;
}
示例11: processRawFieldData
public function processRawFieldData($data, &$status, &$message = null, $simulate = false, $entry_id = null)
{
$status = self::__OK__;
// No file given, save empty data:
if ($data === null) {
return array('file' => null, 'mimetype' => null, 'size' => null, 'meta' => null);
}
// Its not an array, so just retain the current data and return:
if (is_array($data) === false) {
// Ensure the file exists in the `WORKSPACE` directory
// @link http://symphony-cms.com/discuss/issues/view/610/
$file = WORKSPACE . preg_replace(array('%/+%', '%(^|/)\\.\\./%'), '/', $data);
$result = array('file' => $data, 'mimetype' => null, 'size' => null, 'meta' => null);
// Grab the existing entry data to preserve the MIME type and size information
if (isset($entry_id)) {
$row = Symphony::Database()->fetchRow(0, sprintf("SELECT `file`, `mimetype`, `size`, `meta` FROM `tbl_entries_data_%d` WHERE `entry_id` = %d", $this->get('id'), $entry_id));
if (empty($row) === false) {
$result = $row;
}
}
// Found the file, add any missing meta information:
if (file_exists($file) && is_readable($file)) {
if (empty($result['mimetype'])) {
$result['mimetype'] = function_exists('mime_content_type') ? mime_content_type($file) : 'application/octet-stream';
}
if (empty($result['size'])) {
$result['size'] = filesize($file);
}
if (empty($result['meta'])) {
$result['meta'] = serialize(self::getMetaInfo($file, $result['mimetype']));
}
} else {
$message = __('The file uploaded is no longer available. Please check that it exists, and is readable.');
$status = self::__INVALID_FIELDS__;
}
return $result;
}
if ($simulate && is_null($entry_id)) {
return $data;
}
// Check to see if the entry already has a file associated with it:
if (is_null($entry_id) === false) {
$row = Symphony::Database()->fetchRow(0, sprintf("SELECT * FROM `tbl_entries_data_%s` WHERE `entry_id` = %d LIMIT 1", $this->get('id'), $entry_id));
$existing_file = '/' . trim($row['file'], '/');
// File was removed:
if ($data['error'] == UPLOAD_ERR_NO_FILE && !is_null($existing_file) && is_file(WORKSPACE . $existing_file)) {
General::deleteFile(WORKSPACE . $existing_file);
}
}
// Do not continue on upload error:
if ($data['error'] == UPLOAD_ERR_NO_FILE || $data['error'] != UPLOAD_ERR_OK) {
return false;
}
// Where to upload the new file?
$abs_path = DOCROOT . '/' . trim($this->get('destination'), '/');
$rel_path = str_replace('/workspace', '', $this->get('destination'));
// If a file already exists, then rename the file being uploaded by
// adding `_1` to the filename. If `_1` already exists, the logic
// will keep adding 1 until a filename is available (#672)
if (file_exists($abs_path . '/' . $data['name'])) {
$extension = General::getExtension($data['name']);
$new_file = substr($abs_path . '/' . $data['name'], 0, -1 - strlen($extension));
$renamed_file = $new_file;
$count = 1;
do {
$renamed_file = $new_file . '_' . $count . '.' . $extension;
$count++;
} while (file_exists($renamed_file));
// Extract the name filename from `$renamed_file`.
$data['name'] = str_replace($abs_path . '/', '', $renamed_file);
}
// Sanitize the filename
$data['name'] = Lang::createFilename($data['name']);
$file = rtrim($rel_path, '/') . '/' . trim($data['name'], '/');
// Attempt to upload the file:
$uploaded = General::uploadFile($abs_path, $data['name'], $data['tmp_name'], Symphony::Configuration()->get('write_mode', 'file'));
if ($uploaded === false) {
$message = __('There was an error while trying to upload the file %1$s to the target directory %2$s.', array('<code>' . $data['name'] . '</code>', '<code>workspace/' . ltrim($rel_path, '/') . '</code>'));
$status = self::__ERROR_CUSTOM__;
return false;
}
// File has been replaced:
if (isset($existing_file) && strtolower($existing_file) != strtolower($file) && is_file(WORKSPACE . $existing_file)) {
General::deleteFile(WORKSPACE . $existing_file);
}
// If browser doesn't send MIME type (e.g. .flv in Safari)
if (strlen(trim($data['type'])) == 0) {
$data['type'] = function_exists('mime_content_type') ? mime_content_type($file) : 'application/octet-stream';
}
return array('file' => $file, 'size' => $data['size'], 'mimetype' => $data['type'], 'meta' => serialize(self::getMetaInfo(WORKSPACE . $file, $data['type'])));
}