本文整理汇总了PHP中JFile::makeSafe方法的典型用法代码示例。如果您正苦于以下问题:PHP JFile::makeSafe方法的具体用法?PHP JFile::makeSafe怎么用?PHP JFile::makeSafe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JFile
的用法示例。
在下文中一共展示了JFile::makeSafe方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: delete
/**
* Method to delete record(s)
*
* @access public
* @param array $pks
* @return boolean True on success
*/
function delete(&$pks)
{
$row = $this->getTable();
if (count($pks)) {
foreach ($pks as $cid) {
$query = $this->_db->getQuery(true)->select('*')->from($this->_db->quoteName('#__eventgallery_file'))->where('id=' . $this->_db->quote($cid));
$this->_db->setQuery($query);
$data = $this->_db->loadObject();
$path = JPATH_SITE . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'eventgallery' . DIRECTORY_SEPARATOR . JFile::makeSafe($data->folder) . DIRECTORY_SEPARATOR;
$filename = JFile::makeSafe($data->file);
$file = $path . $filename;
if (file_exists($file) && !is_dir($file)) {
if (!unlink($file)) {
echo $file;
return false;
}
}
if (!$row->delete($cid)) {
$this->setError($row->getErrorMsg());
return false;
}
}
}
return true;
}
示例3: loadJSfile
function loadJSfile($file)
{
jimport('joomla.filesystem.file');
$file = JFile::makeSafe($file);
$pa = pathinfo($file);
$fullpath = JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'assets' . DS . 'js' . DS . $file;
if (!empty($pa['extension'])) {
if ($pa['extension'] == 'js') {
//http://php.net/manual/en/function.header.php
if (strstr($_SERVER["HTTP_USER_AGENT"], "MSIE") == false) {
@header("Content-type: text/javascript");
@header("Content-Disposition: inline; filename=\"" . $file . "\"");
//@header("Content-Length: ".filesize($fullpath));
} else {
@header("Content-type: application/force-download");
@header("Content-Disposition: attachment; filename=\"" . $file . "\"");
//@header("Content-Length: ".filesize($fullpath));
}
@header("Expires: Fri, 01 Jan 2010 05:00:00 GMT");
if (strstr($_SERVER["HTTP_USER_AGENT"], "MSIE") == false) {
@header("Cache-Control: no-cache");
@header("Pragma: no-cache");
}
//include(JPATH_SITE.DS.'components'.DS.'com_onepage'.DS.'assets'.DS.'js'.DS.$file);
echo file_get_contents($fullpath);
$doc = JFactory::getApplication();
$doc->close();
die;
}
}
}
示例4: subir
public function subir()
{
$jinput = JFactory::getApplication()->input;
/**
* Esta tarea debe accionarse sólamente cuándo el artículo ha sido previamente guardado,
* con el fin de evitar subir archivos huerfanos
*/
$id = $jinput->get->get('id', null, null);
if ($id == 0) {
print_r('Debe haber guardado el artículo para agregar adjuntos');
return;
}
// Obtiene la variable @campo enviada en el request
$campo = $jinput->get->get('campo', null, null);
$archivo = $jinput->files->get($campo);
if (isset($archivo)) {
// Sanea el nombre de archivo evitando caracteres no deseados
$nombreArchivo = strtolower(JFile::makeSafe($archivo['name']));
// Define el origen y destino del archivo
// TODO: Crear directorio propio para los adjuntos del artículo
// y usarlo como path destino.
$src = $archivo['tmp_name'];
$dest = JPATH_ROOT . DS . 'uploads' . DS . sha1(time()) . '-' . $nombreArchivo;
if (JFile::upload($src, $dest)) {
// TODO: Implementa/valida una estructura de datos para los nombres
// de los archivos que se guardan en la base de datos
print_r("Archivo Subido");
} else {
print_r("Ha ocurrido un error");
print_r($archivo['error']);
}
}
}
示例5: 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;
}
示例6: saveCategoryData
public function saveCategoryData($post)
{
//print_r($post); die;
$db = JFactory::getDbo();
$creationDate = date('Y-m-d H:i:s');
$query = $db->getQuery(true);
$allawExtation = array('jpg', 'jpeg', 'png', 'gif');
# These extantion allowed for upload logo file
$file = JRequest::getVar('categoryLogo', null, 'files', 'array');
$filename = JFile::makeSafe($file['name']);
$filextantion = strtolower(JFile::getExt($filename));
$fileScr = $file['tmp_name'];
$error = $this->validate($post, $filename, $filextantion, $allawExtation, $fileScr);
if (count($error) == 0) {
// Logo update start there
if ($filename != '') {
$tempFname = time() . '.' . $filextantion;
$logoName = str_replace(' ', '', $post['categoryName']) . '_' . $tempFname;
# File name to store into database
$src = $fileScr;
$dest = JPATH_BASE . "/images/productLogo/" . $logoName;
if (JFile::upload($src, $dest)) {
$conditional = $logoName;
}
}
$columns = array('categoryName', 'categoryImage', 'creationDate');
$values = array($db->quote($post['categoryName']), $db->quote($conditional), $db->quote($creationDate));
$query->insert($db->quoteName('onm_product_category'))->columns($db->quoteName($columns))->values(implode(',', $values));
$db->setQuery($query);
$result = $db->execute();
echo "<SCRIPT LANGUAGE='JavaScript'>\n window.alert('Category Added')\n window.location.href='index.php?option=com_membercheckin&view=addcategory';\n </SCRIPT>";
} else {
return $error;
}
}
示例7: upload
function upload($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
$filename = JFile::makeSafe($file['name']);
$filename = str_replace(' ', '-', $filename);
//Set up the source and destination of the file
$src = $file['tmp_name'];
$dest = $path . $filename;
//First check if the file has the right extension, we need jpg only
$ext = strtolower(JFile::getExt($filename));
if ($ext == 'jpg' or $ext == 'gif' or $ext == 'png' or $ext == 'jpeg') {
//check exits
if (!$override) {
if (JFile::exists($dest)) {
echo "<script> alert('Image {$filename} exists on server');\r\n\t\t\t\t\t\twindow.history.go(-1); </script>\n";
exit;
}
}
if (JFile::upload($src, $dest)) {
return $filename;
} else {
echo "<script> alert('Error upload image');\r\n\t\t\twindow.history.go(-1); </script>\n";
exit;
}
} else {
echo "<script> alert('Chi cho phep cac loai anh: jpg, gif, png');\r\n\t\t\twindow.history.go(-1); </script>\n";
exit;
}
return false;
}
示例8: uploadFile
/**
* Upload Simple File Manager files in the right folder.
*
* @param string $tmp_name
* Temporary path of the uploaded file on the server
* @param string $file_name
* Name of the uploaded file
* @return uploaded file path (in case of success) or false (in case of error)
*/
public static function uploadFile($tmp_name, $file_name)
{
jimport('joomla.filesystem.file');
$src = $tmp_name;
$dest = JPATH_COMPONENT_ADMINISTRATOR . DIRECTORY_SEPARATOR . "uploads" . DIRECTORY_SEPARATOR . uniqid("", true) . DIRECTORY_SEPARATOR . JFile::makeSafe(JFile::getName($file_name));
return JFile::upload($src, $dest) ? $dest : false;
}
示例9: 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;
}
示例10: uploadIcon
/**
* Upload an icon for a work
*
* @param KCommandContext A command context object
* @return void
*/
public function uploadIcon(KCommandContext $context)
{
$icon = KRequest::get('files.icon', 'raw');
if (!$icon['name']) {
return;
}
//Prepare MediaHelper
JLoader::register('MediaHelper', JPATH_ROOT . '/components/com_media/helpers/media.php');
// is it an image
if (!MediaHelper::isImage($icon['name'])) {
JError::raiseWarning(21, sprintf(JText::_("%s failed to upload because it's not an image."), $icon['name']));
return;
}
// are we allowed to upload this filetype
if (!MediaHelper::canUpload($icon, $error)) {
JError::raiseWarning(21, sprintf(JText::_("%s failed to upload because %s"), $icon['name'], lcfirst($error)));
return;
}
$slug = $this->getService('koowa:filter.slug');
$path = 'images/com_portfolio/work/' . $slug->sanitize($context->data->title) . '/icon/';
$ext = JFile::getExt($icon['name']);
$name = JFile::makeSafe($slug->sanitize($context->data->title) . '.' . $ext);
JFile::upload($icon['tmp_name'], JPATH_ROOT . '/' . $path . $name);
$context->data->icon = $path . $name;
}
示例11: createThumb
public static function createThumb($path, $width = 100, $height = 100, $crop = 2)
{
$myImage = new JImage();
$myImage->loadFile(JPATH_SITE . DS . $path);
if ($myImage->isLoaded()) {
// $filename = end(explode('/', $path));
$filename = JFile::getName($path);
$filefolder = substr(md5(self::getFolderPath($path)), 1, 10);
$newfilename = $width . 'x' . $height . '_' . $filefolder . '_' . JFile::makeSafe($filename);
$fileExists = JFile::exists(JPATH_CACHE . '/' . $newfilename);
if (!$fileExists) {
$resizedImage = $myImage->resize($width, $height, true, $crop);
$properties = $myImage->getImageFileProperties($path);
$mime = $properties->mime;
if ($mime == 'image/jpeg') {
$type = IMAGETYPE_JPEG;
} elseif ($mime = 'image/png') {
$type = IMAGETYPE_PNG;
} elseif ($mime = 'image/gif') {
$type = IMAGETYPE_GIF;
}
$resizedImage->toFile(JPATH_CACHE . '/' . $newfilename, $type);
}
return $newfilename;
} else {
return "My file is not loaded";
}
}
示例12: check
/**
* Method to perform sanity checks on the JTable instance properties to ensure
* they are safe to store in the database. Child classes should override this
* method to make sure the data they are storing in the database is safe and
* as expected before storage.
*
* @return boolean True if the instance is sane and able to be stored in the database.
*
* @link http://docs.joomla.org/JTable/check
* @since 11.1
*/
public function check()
{
$input = JFactory::getApplication()->input;
$file = $input->files->get('jform', '', 'ARRAY');
$post = $input->post->get('jform', '', 'ARRAY');
$bookId = $post['book_id'];
$file = $file['audio_upload'];
if (empty($file['error'])) {
// Make the filename safe
$audioFile = JFile::makeSafe($file['name']);
$fileExt = explode('.', $audioFile);
if (isset($audioFile)) {
$filepath = JPath::clean(JPATH_SITE . '/media/englishconcept/media/audio/' . strtolower(md5($bookId . $file['name'])) . '.' . $fileExt[1]);
$objectFile = new JObject($file);
$objectFile->filepath = $filepath;
if (JFile::exists($objectFile->filepath)) {
JFile::delete($objectFile->filepath);
}
if (!JFile::upload($objectFile->tmp_name, $objectFile->filepath)) {
return false;
}
}
}
return true;
}
示例13: 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;
}
示例14: display
/**
* K2importViewSelectcategory view display method
* The view for selecting the Main Category for the import and to configure the import
* @return void
**/
function display($tpl = null)
{
JToolBarHelper::title(JText::_('K2 Import Tool') . ' - ' . JText::_('configure the import'), 'generic.png');
// $data =& $this->get( 'Data');
$model =& $this->getModel();
$modus = JRequest::getVar('modus', '', 'get', 'string');
if ($modus == 'archive') {
$mainframe = JFactory::getApplication();
$file = JFolder::files($mainframe->getCfg('tmp_path') . DS . 'k2_import', '.csv');
$this->assignRef('file', $file);
$this->assignRef('modus', $modus);
} else {
$file = JRequest::getVar('file', '', 'get', 'string');
$file = JFile::makeSafe($file);
$this->assignRef('file', $file);
}
$k2categories = $model->getK2categories();
$k2extrafieldgroups = $model->getK2extrafieldgroups();
$this->assignRef('k2extrafieldgroups', $k2extrafieldgroups);
$this->assignRef('k2categories', $k2categories);
$document =& JFactory::getDocument();
$document->addStyleSheet('components/com_k2import/css/k2import.css');
if (version_compare(JVERSION, '1.6.0', 'ge')) {
$document->addScript('components/com_k2import/js/k2import_1_6.js');
} else {
$document->addScript('components/com_k2import/js/k2import_1_5.js');
}
parent::display($tpl);
}
示例15: makeSafe
/**
* Makes file name safe to use
* @param string The name of the file (not full path)
* @return string The sanitised string
*/
function makeSafe($file)
{
jimport('joomla.filesystem.file');
$file = trim($file);
$file = JFile::makeSafe($file);
$file = preg_replace('#\\s#', '', $file);
return $file;
}