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


PHP vRequest::getFiles方法代码示例

本文整理汇总了PHP中vRequest::getFiles方法的典型用法代码示例。如果您正苦于以下问题:PHP vRequest::getFiles方法的具体用法?PHP vRequest::getFiles怎么用?PHP vRequest::getFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vRequest的用法示例。


在下文中一共展示了vRequest::getFiles方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: uploadFile

 /**
  * Handles the upload process of a media, sets the mime_type, when success
  *
  * @author Max Milbers
  * @param string $urlfolder relative url of the folder where to store the media
  * @return name of the uploaded file
  */
 function uploadFile($urlfolder, $overwrite = false)
 {
     if (empty($urlfolder) or strlen($urlfolder) < 2) {
         vmError('Not able to upload file, give path/url empty/too short ' . $urlfolder . ' please correct path in your virtuemart config');
         return false;
     }
     if (!class_exists('JFile')) {
         require VMPATH_LIBS . DS . 'joomla' . DS . 'filesystem' . DS . 'file.php';
     }
     $media = vRequest::getFiles('upload');
     if (empty($media)) {
         vmError('Recieved no data for upload', 'Recieved no data for upload');
         vmdebug('no data in uploadFile ', $_FILES);
         return false;
     }
     $app = JFactory::getApplication();
     switch ($media['error']) {
         case 0:
             $path_folder = str_replace('/', DS, $urlfolder);
             //Sadly it does not work to upload unicode files,
             // the ä for example is stored on windows as ä, this seems to be a php issue (maybe a config setting)
             /*	$dotPos = strrpos($media['name'],'.');
             				$safeMediaName = vmFile::makeSafe( $media['name'] );
             				if($dotPos!==FALSE){
             					$mediaPure = substr($media['name'],0,$dotPos);
             					$mediaExtension = strtolower(substr($media['name'],$dotPos));
             				}
             			*/
             $safeMediaName = vmFile::makeSafe($media['name']);
             $media['name'] = $safeMediaName;
             $mediaPure = JFile::stripExt($media['name']);
             $mediaExtension = '.' . strtolower(JFile::getExt($media['name']));
             vmdebug('uploadFile $safeMediaName', $media['name'], $safeMediaName, $mediaPure, $mediaExtension);
             if (!$overwrite) {
                 while (file_exists(VMPATH_ROOT . DS . $path_folder . $mediaPure . $mediaExtension)) {
                     $mediaPure = $mediaPure . rand(1, 9);
                 }
             }
             $media['name'] = $this->file_name = $mediaPure . $mediaExtension;
             if ($this->file_is_forSale == 0) {
                 JFile::upload($media['tmp_name'], VMPATH_ROOT . DS . $path_folder . $media['name']);
             } else {
                 JFile::upload($media['tmp_name'], $path_folder . $media['name']);
             }
             $this->file_mimetype = $media['type'];
             $this->media_published = 1;
             $app->enqueueMessage(vmText::sprintf('COM_VIRTUEMART_FILE_UPLOAD_OK', VMPATH_ROOT . DS . $path_folder . $media['name']));
             return $media['name'];
         case 1:
             //uploaded file exceeds the upload_max_filesize directive in php.ini
             $app->enqueueMessage(vmText::sprintf('COM_VIRTUEMART_PRODUCT_FILES_ERR_UPLOAD_MAX_FILESIZE', $media['name'], $media['tmp_name']), 'warning');
             break;
         case 2:
             //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
             $app->enqueueMessage(vmText::sprintf('COM_VIRTUEMART_PRODUCT_FILES_ERR_MAX_FILE_SIZE', $media['name'], $media['tmp_name']), 'warning');
             break;
         case 3:
             //uploaded file was only partially uploaded
             $app->enqueueMessage(vmText::sprintf('COM_VIRTUEMART_PRODUCT_FILES_ERR_PARTIALLY', $media['name'], $media['tmp_name']), 'warning');
             break;
         case 4:
             //no file was uploaded
             //$vmLogger->warning( "You have not selected a file/image for upload." );
             break;
         default:
             //a default error, just in case!  :)
             //$vmLogger->warning( "There was a problem with your upload." );
             break;
     }
     return false;
 }
开发者ID:sam-akopyan,项目名称:hamradio,代码行数:78,代码来源:mediahandler.php

示例2: uploadFile

 /**
  * Handles the upload process of a media, sets the mime_type, when success
  *
  * @author Max Milbers
  * @param string $urlfolder relative url of the folder where to store the media
  * @return name of the uploaded file
  */
 static function uploadFile($urlfolder, &$obj, $overwrite = false)
 {
     if (empty($urlfolder) or strlen($urlfolder) < 2) {
         vmError('Not able to upload file, give path/url empty/too short ' . $urlfolder . ' please correct path in your tsmart config');
         return false;
     }
     if (!class_exists('JFile')) {
         require VMPATH_LIBS . DS . 'joomla' . DS . 'filesystem' . DS . 'file.php';
     }
     $media = vRequest::getFiles('upload');
     if (empty($media) or !isset($media['error'])) {
         vmError('Recieved no data for upload', 'Recieved no data for upload');
         vmdebug('no data in uploadFile ', $_FILES);
         return false;
     }
     $app = JFactory::getApplication();
     switch ($media['error']) {
         case 0:
             $path_folder = str_replace('/', DS, $urlfolder);
             //Sadly it does not work to upload unicode files,
             // the � for example is stored on windows as ä, this seems to be a php issue (maybe a config setting)
             /*	$dotPos = strrpos($media['name'],'.');
             				$safeMediaName = vmFile::makeSafe( $media['name'] );
             				if($dotPos!==FALSE){
             					$mediaPure = substr($media['name'],0,$dotPos);
             					$mediaExtension = strtolower(substr($media['name'],$dotPos));
             				}
             			*/
             $safeMediaName = vmFile::makeSafe($media['name']);
             $media['name'] = $safeMediaName;
             $mediaPure = JFile::stripExt($media['name']);
             $mediaExtension = strtolower(JFile::getExt($media['name']));
             if (empty($mediaExtension)) {
                 vmError('Invalid media; no extension ' . $media['name']);
                 return false;
             }
             if (!$overwrite) {
                 $i = 0;
                 while (file_exists(VMPATH_ROOT . DS . $path_folder . $mediaPure . '.' . $mediaExtension) and $i < 20) {
                     $mediaPure = $mediaPure . rand(1, 9);
                     $i++;
                 }
             }
             $media['name'] = $obj->file_name = $mediaPure . '.' . $mediaExtension;
             $type = exif_imagetype($media['tmp_name']);
             if ($type) {
                 vmdebug('Recognised image');
                 if (!self::checkMediaType($type, $mediaExtension)) {
                     vmError('Invalid media, image type does not fit to extension ' . $media['name']);
                     return false;
                 }
             } else {
                 if (!vmAccess::manager('media.potdang')) {
                     $m2ext = self::getMime2ExtArray();
                     $realMime = self::getMimeType($media['tmp_name']);
                     vmdebug('Uploading file $realMime', $realMime, $m2ext);
                     if (isset($m2ext[$realMime])) {
                         //if($rExt = array_search($realMime,$m2ext)!==false){
                         $rExt = $m2ext[$realMime];
                         $hless = self::getSafeExt2MimeArray();
                         vmdebug('Recognised nonimage, not safe ext', $rExt, $hless);
                         //$rExt = $hless[$realMime];
                         if (!isset($hless[$rExt])) {
                             vmError('Invalid media type, you are not allowed to upload this file, file type does not fit to mime ' . $media['name']);
                             return false;
                         } else {
                             vmdebug('Uploading file ', $hless[$rExt]);
                         }
                     } else {
                         return false;
                     }
                 }
             }
             if ($obj->file_is_forSale == 0) {
                 JFile::upload($media['tmp_name'], VMPATH_ROOT . DS . $path_folder . $media['name']);
             } else {
                 JFile::upload($media['tmp_name'], $path_folder . $media['name']);
             }
             $obj->file_mimetype = $media['type'];
             $obj->media_published = 1;
             $app->enqueueMessage(tsmText::sprintf('com_tsmart_FILE_UPLOAD_OK', VMPATH_ROOT . DS . $path_folder . $media['name']));
             return $media['name'];
         case 1:
             //uploaded file exceeds the upload_max_filesize directive in php.ini
             $app->enqueueMessage(tsmText::sprintf('com_tsmart_PRODUCT_FILES_ERR_UPLOAD_MAX_FILESIZE', $media['name'], $media['tmp_name']), 'warning');
             break;
         case 2:
             //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
             $app->enqueueMessage(tsmText::sprintf('com_tsmart_PRODUCT_FILES_ERR_MAX_FILE_SIZE', $media['name'], $media['tmp_name']), 'warning');
             break;
         case 3:
             //uploaded file was only partially uploaded
             $app->enqueueMessage(tsmText::sprintf('com_tsmart_PRODUCT_FILES_ERR_PARTIALLY', $media['name'], $media['tmp_name']), 'warning');
//.........这里部分代码省略.........
开发者ID:cuongnd,项目名称:etravelservice,代码行数:101,代码来源:tsmuploader.php


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