本文整理汇总了PHP中JFile::getExt方法的典型用法代码示例。如果您正苦于以下问题:PHP JFile::getExt方法的具体用法?PHP JFile::getExt怎么用?PHP JFile::getExt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JFile
的用法示例。
在下文中一共展示了JFile::getExt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* Render uploaded image
*
* @param object &$model Element model
* @param object &$params Element params
* @param string $file Row data for this element
* @param object $thisRow All row's data
*
* @return void
*/
public function render(&$model, &$params, $file, $thisRow = null)
{
$src = str_replace("\\", "/", COM_FABRIK_LIVESITE . $file);
$ext = JString::strtolower(JFile::getExt($file));
if (!JPluginHelper::isEnabled('content', 'jw_allvideos')) {
$this->output = JText::_('PLG_ELEMENT_FILEUPLOAD_INSTALL_ALL_VIDEOS');
return;
}
$extra = array();
$extra[] = $src;
if ($this->inTableView || $params->get('fu_show_image') < 2) {
$extra[] = $params->get('thumb_max_width');
$extra[] = $params->get('thumb_max_height');
} else {
$extra[] = $params->get('fu_main_max_width');
$extra[] = $params->get('fu_main_max_height');
}
$src = implode('|', $extra);
switch ($ext) {
case 'flv':
$this->output = "{flvremote}{$src}{/flvremote}";
break;
case '3gp':
$this->output = "{3gpremote}{$src}{/3gpremote}";
break;
case 'divx':
$this->output = "{divxremote}{$src}{/divxremote}";
break;
}
}
示例2: readData
function readData($file)
{
$fileExtension = strtolower(JFile::getExt($file));
$validExtensions = array('jpg', 'jpeg', 'jpe');
$exifArray = array();
if (in_array($fileExtension, $validExtensions)) {
/*if(!extension_loaded('exif'))
{
$phpVersion = phpversion();
if (version_compare($phpVersion, '5.0.0') <= -1)
{
return array();
}
else
{
if ($this->detect())
{
$exifArray = $this->readDataDisabledExif($file);
}
else
{
return array();
}
}
}*/
if (extension_loaded('exif')) {
$exifArray = $this->readDataEnabledExif($file);
}
if (!$exifArray) {
return array();
} else {
return $exifArray;
}
}
}
示例3: uploadAvatar
/**
* Upload the users avatar
*
* @param KCommandContext A command context object
* @return void
*/
public function uploadAvatar(KCommandContext $context)
{
$avatar = KRequest::get('files.avatar', 'raw');
if (!$avatar['name']) {
return;
}
//Prepare MediaHelper
JLoader::register('MediaHelper', JPATH_ROOT . '/components/com_media/helpers/media.php');
// is it an image
if (!MediaHelper::isImage($avatar['name'])) {
JError::raiseWarning(21, sprintf(JText::_("%s failed to upload because it's not an image."), $avatar['name']));
return;
}
// are we allowed to upload this filetype
if (!MediaHelper::canUpload($avatar, $error)) {
JError::raiseWarning(21, sprintf(JText::_("%s failed to upload because %s"), $avatar['name'], lcfirst($error)));
return;
}
// @todo put in some max file size checks
$path = 'images/com_portfolio/avatars/' . $context->data->user_id . '/';
$ext = JFile::getExt($avatar['name']);
$name = JFile::makeSafe($this->getService('koowa:filter.slug')->sanitize($context->data->title) . '.' . $ext);
JFile::upload($avatar['tmp_name'], JPATH_ROOT . '/' . $path . $name);
$context->data->avatar = $path . $name;
}
示例4: render
/**
* @param object element model
* @param object element params
* @param string row data for this element
*/
function render(&$model, &$params, $file)
{
jimport('joomla.filesystem.file');
$filename = basename($file);
$filename = strip_tags($filename);
$ext = JFile::getExt($filename);
//$file = str_replace("\\", "/", COM_FABRIK_LIVESITE . $file);
if (!strstr($file, 'http://') && !strstr($file, 'https://')) {
// $$$rob only add in livesite if we dont already have a full url (eg from amazons3)
// $$$ hugh trim / or \ off the start of $file
$file = JString::ltrim($file, '/\\');
$file = COM_FABRIK_LIVESITE . $file;
}
$file = str_replace("\\", "/", $file);
$file = $model->storage->preRenderPath($file);
$thumb_path = COM_FABRIK_BASE . 'media/com_fabrik/images/' . $ext . '.png';
// $$$ hugh - using 'make_thumbnail' to mean 'use default $ext.png as an icon
// instead of just putting the filename.
if ($params->get('make_thumbnail', false) && JFile::exists($thumb_path)) {
$thumb_file = COM_FABRIK_LIVESITE . "/media/com_fabrik/images/" . $ext . ".png";
$this->output = "<a class=\"download-archive fabrik-filetype-{$ext}\" title=\"{$file}\" href=\"{$file}\"><img src=\"{$thumb_file}\" alt=\"{$filename}\"></a>";
} else {
$this->output = "<a class=\"download-archive fabrik-filetype-{$ext}\" title=\"{$file}\" href=\"{$file}\">" . $filename . "</a>";
}
}
示例5: getValue
function getValue($field, $source_array)
{
jimport('joomla.filesystem.file');
$upload_path = $field->getParam('upload_path', 'media' . DS . APP_EXTENSION . DS . 'files' . DS . $field->db_name);
$allowed_extensions = explode(',', $field->getParam('file_extensions', 'jpg,gif,jpeg,png'));
$delete_file = JArrayHelper::getValue($source_array, "{$field->db_name}_delete", 0, "INT");
if ($delete_file) {
return "";
}
$file = JRequest::getVar($field->db_name . '_replace', null, 'files');
if (!$file['name']) {
$file = JRequest::getVar($field->db_name, null, 'files');
}
$fname = $file['name'];
if (!is_uploaded_file($file['tmp_name'])) {
return null;
}
$ext = strtolower(JFile::getExt($fname));
if (!in_array($ext, $allowed_extensions)) {
return null;
}
$file_name = JFile::makesafe('custom-' . trim($field->db_name) . '-' . time() . ".{$ext}");
JFile::upload($file['tmp_name'], $upload_path . DS . $file_name);
return $file_name;
}
示例6: getInput
protected function getInput()
{
$doc = JFactory::getDocument();
JHtml::_('jquery.framework');
$plg_path = JURI::root(true) . '/plugins/system/helix3';
$doc->addScript($plg_path . '/assets/js/spimage.js');
$doc->addStyleSheet($plg_path . '/assets/css/spimage.css');
if ($this->value) {
$class1 = ' hide';
$class2 = '';
} else {
$class1 = '';
$class2 = ' hide';
}
$output = '<div class="sp-image-field clearfix">';
$output .= '<div class="sp-image-upload-wrapper">';
if ($this->value) {
$data_src = $this->value;
$src = JURI::root(true) . '/' . $data_src;
$basename = basename($data_src);
$thumbnail = JPATH_ROOT . '/' . dirname($data_src) . '/' . JFile::stripExt($basename) . '_thumbnail.' . JFile::getExt($basename);
if (file_exists($thumbnail)) {
$src = JURI::root(true) . '/' . dirname($data_src) . '/' . JFile::stripExt($basename) . '_thumbnail.' . JFile::getExt($basename);
}
$output .= '<img src="' . $src . '" data-src="' . $data_src . '" alt="">';
}
$output .= '</div>';
$output .= '<input type="file" class="sp-image-upload" accept="image/*" style="display:none;">';
$output .= '<a class="btn btn-info btn-sp-image-upload' . $class1 . '" href="#"><i class="fa fa-plus"></i> Upload Image</a>';
$output .= '<a class="btn btn-danger btn-sp-image-remove' . $class2 . '" href="#"><i class="fa fa-minus-circle"></i> Remove Image</a>';
$output .= '<input type="hidden" name="' . $this->name . '" id="' . $this->id . '" value="' . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '" class="form-field-spimage">';
$output .= '</div>';
return $output;
}
示例7: getData
public function getData()
{
ob_clean();
$app = JFactory::getApplication();
$session = JFactory::getSession();
$post = JRequest::get('post');
$files = JRequest::get('files');
$files = $files[$post['task'] . $post['import']];
if (isset($post['task']) && isset($post['import'])) {
if ($files['name'] == "") {
return JText::_('PLEASE_SELECT_FILE');
}
$ext = strtolower(JFile::getExt($files['name']));
if ($ext != 'csv') {
return JText::_('FILE_EXTENSION_WRONG');
}
} else {
if (!isset($post['import'])) {
return JText::_('PLEASE_SELECT_SECTION');
}
}
// Upload csv file
$src = $files['tmp_name'];
$dest = JPATH_ROOT . '/components/com_redshop/assets/importcsv/' . $post['import'] . '/' . $files['name'];
$file_upload = JFile::upload($src, $dest);
$session->clear('ImportPost');
$session->clear('Importfile');
$session->clear('Importfilename');
$session->set('ImportPost', $post);
$session->set('Importfile', $files);
$session->set('Importfilename', $files['name']);
$app->Redirect('index.php?option=com_redshop&view=import&layout=importlog');
return;
}
示例8: install
public function install()
{
// Request forgeries check
JRequest::checkToken() or die('Invalid Token');
$file = JRequest::getVar('rule', '', 'FILES');
$app = JFactory::getApplication();
$files = array();
// @task: If there's no tmp_name in the $file, we assume that the data sent is corrupted.
if (!isset($file['tmp_name'])) {
DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_INVALID_RULE_FILE'), DISCUSS_QUEUE_ERROR);
$app->redirect('index.php?option=com_easydiscuss&view=rules&layout=install');
$app->close();
}
// There are various MIME type for compressed file. So let's check the file extension instead.
if ($file['name'] && JFile::getExt($file['name']) == 'xml') {
$files = array($file['tmp_name']);
} else {
$jConfig = DiscussHelper::getJConfig();
$path = rtrim($jConfig->get('tmp_path'), '/') . '/' . $file['name'];
// @rule: Copy zip file to temporary location
if (!JFile::copy($file['tmp_name'], $path)) {
DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_INVALID_RULE_FILE'), DISCUSS_QUEUE_ERROR);
$app->redirect('index.php?option=com_easydiscuss&view=rules&layout=install');
$app->close();
}
jimport('joomla.filesystem.archive');
$tmp = md5(DiscussHelper::getDate()->toMysQL());
$dest = rtrim($jConfig->get('tmp_path'), '/') . '/' . $tmp;
if (!JArchive::extract($path, $dest)) {
DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_INVALID_RULE_FILE'), DISCUSS_QUEUE_ERROR);
$app->redirect('index.php?option=com_easydiscuss&view=rules&layout=install');
$app->close();
}
$files = JFolder::files($dest, '.', true, true);
if (empty($files)) {
// Try to do a level deeper in case the zip is on the outer.
$folder = JFolder::folders($dest);
if (!empty($folder)) {
$files = JFolder::files($dest . '/' . $folder[0], true);
$dest = $dest . '/' . $folder[0];
}
}
if (empty($files)) {
DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_INVALID_RULE_FILE'), DISCUSS_QUEUE_ERROR);
$app->redirect('index.php?option=com_easydiscuss&view=rules&layout=install');
$app->close();
}
}
if (empty($files)) {
DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_RULE_INSTALL_FAILED'), DISCUSS_QUEUE_ERROR);
$app->redirect('index.php?option=com_easydiscuss&view=rules&layout=install');
$app->close();
}
foreach ($files as $file) {
$this->installXML($file);
}
DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_RULE_INSTALL_SUCCESS'), DISCUSS_QUEUE_SUCCESS);
$app->redirect('index.php?option=com_easydiscuss&view=rules&layout=install');
$app->close();
}
示例9: createThumbnail
/**
* Create a thumbnail from an image file.
*
* <code>
* $myFile = "/tmp/myfile.jpg";
*
* $options = array(
* "destination" => "image/mypic.jpg",
* "width" => 200,
* "height" => 200,
* "scale" => JImage::SCALE_INSIDE
* );
*
* $file = new PrismFileImage($myFile);
* $file->createThumbnail($options);
*
* </code>
*
* @param array $options Some options used in the process of generating thumbnail.
*
* @throws \InvalidArgumentException
* @throws \RuntimeException
*
* @return string A location to the new file.
*/
public function createThumbnail($options)
{
$width = ArrayHelper::getValue($options, "width", 100);
$height = ArrayHelper::getValue($options, "height", 100);
$scale = ArrayHelper::getValue($options, "scale", \JImage::SCALE_INSIDE);
$destination = ArrayHelper::getValue($options, "destination");
if (!$destination) {
throw new \InvalidArgumentException(\JText::_("LIB_PRISM_ERROR_INVALID_FILE_DESTINATION"));
}
// Generate thumbnail.
$image = new \JImage();
$image->loadFile($this->file);
if (!$image->isLoaded()) {
throw new \RuntimeException(\JText::sprintf('LIB_PRISM_ERROR_FILE_NOT_FOUND', $this->file));
}
// Resize the file as a new object
$thumb = $image->resize($width, $height, true, $scale);
$fileName = basename($this->file);
$ext = \JString::strtolower(\JFile::getExt(\JFile::makeSafe($fileName)));
switch ($ext) {
case "gif":
$type = IMAGETYPE_GIF;
break;
case "png":
$type = IMAGETYPE_PNG;
break;
case IMAGETYPE_JPEG:
default:
$type = IMAGETYPE_JPEG;
}
$thumb->toFile($destination, $type);
return $destination;
}
示例10: render
/**
* Render a file in form/details view, stored data in $this->output
*
* @param object &$model Element model
* @param object &$params Element params
* @param string $file Row data for this element
*
* @return void
*/
public function render(&$model, &$params, $file)
{
jimport('joomla.filesystem.file');
/*
* $$$ hugh - TESTING - if $file is empty, we're going to just build an empty bit of DOM
* which can then be filled in with the selected image using HTML5 in browser.
*/
if (empty($file)) {
if ($params->get('make_thumbnail', false)) {
$maxWidth = $params->get('thumb_max_width', 125);
$maxHeight = $params->get('thumb_max_height', 125);
$this->output .= '<img style="width: ' . $maxWidth . 'px;" src="" alt="" />';
}
} else {
$filename = basename($file);
$filename = strip_tags($filename);
$ext = JFile::getExt($filename);
if (!strstr($file, 'http://') && !strstr($file, 'https://')) {
// $$$rob only add in livesite if we don't already have a full url (e.g. from amazons3)
// Trim / or \ off the start of $file
$file = JString::ltrim($file, '/\\');
$file = COM_FABRIK_LIVESITE . $file;
}
$file = str_replace("\\", "/", $file);
$file = $model->storage->preRenderPath($file);
$layout = $model->getLayout('file');
$displayData = new stdClass();
$displayData->thumb = COM_FABRIK_LIVESITE . 'media/com_fabrik/images/' . $ext . '.png';
$displayData->useThumb = $params->get('make_thumbnail', false) && JFile::exists($displayData->thumb);
$displayData->ext = $ext;
$displayData->filename = $filename;
$displayData->file = $file;
$this->output = $layout->render($displayData);
}
}
示例11: uploadFiles
public function uploadFiles($files, $options)
{
$result = array();
$destination = JArrayHelper::getValue($options, "destination");
$maxSize = JArrayHelper::getValue($options, "max_size");
$legalExtensions = JArrayHelper::getValue($options, "legal_extensions");
$legalFileTypes = JArrayHelper::getValue($options, "legal_types");
// check for error
foreach ($files as $fileData) {
// Upload image
if (!empty($fileData['name'])) {
$uploadedFile = JArrayHelper::getValue($fileData, 'tmp_name');
$uploadedName = JArrayHelper::getValue($fileData, 'name');
$errorCode = JArrayHelper::getValue($fileData, 'error');
$file = new Prism\File\File();
// Prepare size validator.
$KB = 1024 * 1024;
$fileSize = JArrayHelper::getValue($fileData, "size");
$uploadMaxSize = $maxSize * $KB;
// Prepare file size validator
$sizeValidator = new Prism\File\Validator\Size($fileSize, $uploadMaxSize);
// Prepare server validator.
$serverValidator = new Prism\File\Validator\Server($errorCode, array(UPLOAD_ERR_NO_FILE));
// Prepare image validator.
$typeValidator = new Prism\File\Validator\Type($uploadedFile, $uploadedName);
// Get allowed MIME types.
$mimeTypes = explode(",", $legalFileTypes);
$mimeTypes = array_map('trim', $mimeTypes);
$typeValidator->setMimeTypes($mimeTypes);
// Get allowed file extensions.
$fileExtensions = explode(",", $legalExtensions);
$fileExtensions = array_map('trim', $fileExtensions);
$typeValidator->setLegalExtensions($fileExtensions);
$file->addValidator($sizeValidator)->addValidator($typeValidator)->addValidator($serverValidator);
// Validate the file
if (!$file->isValid()) {
throw new RuntimeException($file->getError());
}
// Generate file name
$baseName = JString::strtolower(JFile::makeSafe(basename($fileData['name'])));
$ext = JFile::getExt($baseName);
$generatedName = new Prism\String();
$generatedName->generateRandomString(6);
$destinationFile = $destination . DIRECTORY_SEPARATOR . $generatedName . "." . $ext;
// Prepare uploader object.
$uploader = new Prism\File\Uploader\Local($uploadedFile);
$uploader->setDestination($destinationFile);
// Upload temporary file
$file->setUploader($uploader);
$file->upload();
// Get file
$fileSource = $file->getFile();
if (!JFile::exists($fileSource)) {
throw new RuntimeException(JText::_("COM_CROWDFUNDING_ERROR_FILE_CANT_BE_UPLOADED"));
}
$result[] = array("title" => $baseName, "filename" => basename($fileSource));
}
}
return $result;
}
示例12: _getSubscriberCSV
function _getSubscriberCSV()
{
$keys = array();
$subscribers = array();
$subscriber = array();
jimport('joomla.filesystem.file');
$allowedExts = array('csv');
$csvFile = $_FILES['csv_subscribers'];
$csvFileName = $csvFile['tmp_name'];
$fileName = $csvFile['name'];
$fileExt = strtolower(JFile::getExt($fileName));
if (in_array($fileExt, $allowedExts)) {
$line = 0;
$fp = fopen($csvFileName, 'r');
while (($cells = fgetcsv($fp)) !== FALSE) {
if ($line == 0) {
foreach ($cells as $key) {
$keys[] = $key;
}
$line++;
} else {
$i = 0;
foreach ($cells as $cell) {
$subscriber[$keys[$i]] = $cell;
$i++;
}
$subscribers[] = $subscriber;
}
}
fclose($fp);
return $subscribers;
}
}
示例13: checkUpload
/**
* checks uploaded file, and uploads it
* @return true csv file uploaded ok, false error (JErrir warning raised)
*/
function checkUpload()
{
if (!(bool) ini_get('file_uploads')) {
JError::raiseWarning(500, JText::_("The installer can't continue before file uploads are enabled. Please use the install from directory method."));
return false;
}
$userfile = JRequest::getVar('userfile', null, 'files');
if (!$userfile) {
JError::raiseWarning(500, JText::_('No file selected'));
return false;
}
jimport('joomla.filesystem.file');
$allowed = array('txt', 'csv', 'tsv');
if (!in_array(JFile::getExt($userfile['name']), $allowed)) {
JError::raiseError(500, 'File must be a csv file');
return false;
}
$config =& JFactory::getConfig();
$tmp_dir = $config->getValue('config.tmp_path');
if (empty($tmp_dir) || !JFolder::exists($tmp_dir)) {
JError::raiseError(500, 'Joomla tmp_path not configured or does not exist');
return false;
}
$tmp_name = 'fabrik_csv_' . md5(uniqid());
$to = JPath::clean($tmp_dir . DS . $tmp_name);
$resultdir = JFile::upload($userfile['tmp_name'], $to);
if ($resultdir === false) {
JError::raiseWarning(500, JText::_('Upload Error'));
return false;
}
return $tmp_name;
}
示例14: loaddata
/**
* Process sampledata
*
* @access public
* @return true on success
* @since 0.9
*/
function loaddata()
{
//determine sql file
foreach ($this->_filelist['files'] as $key => $file) {
if (JFile::getExt($file) == 'sql') {
$scriptfile = $file;
unset($this->_filelist['files'][$key]);
}
}
//load sql file
if (!($buffer = file_get_contents($this->_filelist['folder'] . DS . $scriptfile))) {
return false;
}
//extract queries out of sql file
$queries = $this->_splitSql($buffer);
//Process queries
foreach ($queries as $query) {
$query = trim($query);
if ($query != '' && $query[0] != '#') {
$this->_db->setQuery($query);
$this->_db->query();
}
}
//move images in proper directory
$this->_moveimages();
//delete temporary extraction folder
if (!$this->_deletetmp()) {
JError::raiseWarning('SOME ERROR CODE', JText::_('UNABLE TO DELETE TMP FOLDER'));
}
return true;
}
示例15: uploadImage
function uploadImage($file, $path, $override = 0)
{
//Import filesystem libraries. Perhaps not necessary, but does not hurt
jimport('joomla.filesystem.file');
//Clean up filename to get rid of strange characters like spaces etc
$filenameTmp = JFile::makeSafe($file['name']);
$ext = strtolower(JFile::getExt($filenameTmp));
$filename = str_replace(' ', '-', JFile::stripExt($filenameTmp)) . '.' . $ext;
$src = $file['tmp_name'];
$dest = $path . $filename;
//First check if the file has the right extension, we need jpg only
if ($ext == 'jpg' or $ext == 'gif' or $ext == 'png' or $ext == 'jpeg' or $ext == 'zip' or $ext = 'rar' or $ext = 'pdf') {
//check exits
if (!$override) {
if (JFile::exists($dest)) {
$dest = checkExists($filenameTmp, $ext);
}
}
if (JFile::upload($src, $dest)) {
return $filename;
} else {
echo "Error upload image";
exit;
}
} else {
echo "Chi cho phep cac loai anh: jpg, gif, png";
exit;
}
return false;
}