当前位置: 首页>>代码示例>>PHP>>正文


PHP JFile::makeSafe方法代码示例

本文整理汇总了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;
}
开发者ID:geilin,项目名称:jooomlashop,代码行数:30,代码来源:functions.php

示例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;
 }
开发者ID:sansandeep143,项目名称:av,代码行数:32,代码来源:file.php

示例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;
         }
     }
 }
开发者ID:aldegtyarev,项目名称:stelsvelo,代码行数:31,代码来源:mini.php

示例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']);
         }
     }
 }
开发者ID:networksoft,项目名称:seekerplus2.com,代码行数:33,代码来源:adjuntos.php

示例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;
 }
开发者ID:pashakiz,项目名称:crowdf,代码行数:60,代码来源:files.php

示例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;
     }
 }
开发者ID:ranrolls,项目名称:php-web-offers-portal,代码行数:35,代码来源:addcategory.php

示例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;
 }
开发者ID:geilin,项目名称:jooomlashop,代码行数:32,代码来源:admin.products.class.php

示例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;
 }
开发者ID:gmansillo,项目名称:simplefilemanager,代码行数:16,代码来源:simplefilemanager.php

示例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;
 }
开发者ID:ravenlife,项目名称:Portfolio,代码行数:31,代码来源:person.php

示例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;
 }
开发者ID:ravenlife,项目名称:Portfolio,代码行数:31,代码来源:work.php

示例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";
     }
 }
开发者ID:quyip8818,项目名称:joomla,代码行数:28,代码来源:helper.php

示例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;
 }
开发者ID:prox91,项目名称:joomla-dev,代码行数:36,代码来源:lesson.php

示例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;
 }
开发者ID:pashakiz,项目名称:crowdf,代码行数:58,代码来源:Image.php

示例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);
 }
开发者ID:Gskflute,项目名称:joomla25,代码行数:34,代码来源:view.html.php

示例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;
 }
开发者ID:rlee1962,项目名称:diylegalcenter,代码行数:13,代码来源:utils.php


注:本文中的JFile::makeSafe方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。