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


PHP TBGSettings::getUploadsEffectiveMaxSize方法代码示例

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


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

示例1: handleUpload

 /**
  * Handles an uploaded file, stores it to the correct folder, adds an entry
  * to the database and returns a TBGFile object
  * 
  * @param string $thefile The request parameter the file was sent as
  * 
  * @return TBGFile The TBGFile object
  */
 public function handleUpload($key)
 {
     $apc_exists = self::CanGetUploadStatus();
     if ($apc_exists && !array_key_exists($this->getParameter('APC_UPLOAD_PROGRESS'), $_SESSION['__upload_status'])) {
         $_SESSION['__upload_status'][$this->getParameter('APC_UPLOAD_PROGRESS')] = array('id' => $this->getParameter('APC_UPLOAD_PROGRESS'), 'finished' => false, 'percent' => 0, 'total' => 0, 'complete' => 0);
     }
     try {
         if ($this->getUploadedFile($key) !== null) {
             $thefile = $this->getUploadedFile($key);
             if (TBGSettings::isUploadsEnabled()) {
                 TBGLogging::log('Uploads enabled');
                 if ($thefile['error'] == UPLOAD_ERR_OK) {
                     TBGLogging::log('No upload errors');
                     if (filesize($thefile['tmp_name']) > TBGSettings::getUploadsEffectiveMaxSize(true)) {
                         throw new Exception(TBGContext::getI18n()->__('You cannot upload files bigger than %max_size MB', array('%max_size' => TBGSettings::getUploadsEffectiveMaxSize())));
                     }
                     TBGLogging::log('Upload filesize ok');
                     $extension = mb_substr(basename($thefile['name']), mb_strrpos(basename($thefile['name']), '.'));
                     if ($extension == '') {
                         TBGLogging::log('OOps, could not determine upload filetype', 'main', TBGLogging::LEVEL_WARNING_RISK);
                         //throw new Exception(TBGContext::getI18n()->__('Could not determine filetype'));
                     } else {
                         TBGLogging::log('Checking uploaded file extension');
                         $extension = mb_substr($extension, 1);
                         $upload_extensions = TBGSettings::getUploadsExtensionsList();
                         if (TBGSettings::getUploadsRestrictionMode() == 'blacklist') {
                             TBGLogging::log('... using blacklist');
                             foreach ($upload_extensions as $an_ext) {
                                 if (mb_strtolower(trim($extension)) == mb_strtolower(trim($an_ext))) {
                                     TBGLogging::log('Upload extension not ok');
                                     throw new Exception(TBGContext::getI18n()->__('This filetype is not allowed'));
                                 }
                             }
                             TBGLogging::log('Upload extension ok');
                         } else {
                             TBGLogging::log('... using whitelist');
                             $is_ok = false;
                             foreach ($upload_extensions as $an_ext) {
                                 if (mb_strtolower(trim($extension)) == mb_strtolower(trim($an_ext))) {
                                     TBGLogging::log('Upload extension ok');
                                     $is_ok = true;
                                     break;
                                 }
                             }
                             if (!$is_ok) {
                                 TBGLogging::log('Upload extension not ok');
                                 throw new Exception(TBGContext::getI18n()->__('This filetype is not allowed'));
                             }
                         }
                         /*if (in_array(mb_strtolower(trim($extension)), array('php', 'asp')))
                         		{
                         			TBGLogging::log('Upload extension is php or asp');
                         			throw new Exception(TBGContext::getI18n()->__('This filetype is not allowed'));
                         		}*/
                     }
                     if (is_uploaded_file($thefile['tmp_name'])) {
                         TBGLogging::log('Uploaded file is uploaded');
                         $new_filename = TBGContext::getUser()->getID() . '_' . NOW . '_' . basename($thefile['name']);
                         if (TBGSettings::getUploadStorage() == 'files') {
                             $files_dir = TBGSettings::getUploadsLocalpath();
                             $filename = $files_dir . $new_filename;
                         } else {
                             $filename = $thefile['tmp_name'];
                         }
                         TBGLogging::log('Moving uploaded file to ' . $filename);
                         if (TBGSettings::getUploadStorage() == 'files' && !move_uploaded_file($thefile['tmp_name'], $filename)) {
                             TBGLogging::log('Moving uploaded file failed!');
                             throw new Exception(TBGContext::getI18n()->__('An error occured when saving the file'));
                         } else {
                             TBGLogging::log('Upload complete and ok, storing upload status and returning filename ' . $new_filename);
                             $content_type = TBGFile::getMimeType($filename);
                             $file = new TBGFile();
                             $file->setRealFilename($new_filename);
                             $file->setOriginalFilename(basename($thefile['name']));
                             $file->setContentType($content_type);
                             $file->setDescription($this->getParameter($key . '_description'));
                             $file->setUploadedBy(TBGContext::getUser());
                             if (TBGSettings::getUploadStorage() == 'database') {
                                 $file->setContent(file_get_contents($filename));
                             }
                             $file->save();
                             if ($apc_exists) {
                                 $_SESSION['__upload_status'][$this->getParameter('APC_UPLOAD_PROGRESS')] = array('id' => $this->getParameter('APC_UPLOAD_PROGRESS'), 'finished' => true, 'percent' => 100, 'total' => 0, 'complete' => 0, 'file_id' => $file->getID());
                             }
                             return $file;
                         }
                     } else {
                         TBGLogging::log('Uploaded file was not uploaded correctly');
                         throw new Exception(TBGContext::getI18n()->__('The file was not uploaded correctly'));
                     }
                 } else {
                     TBGLogging::log('Upload error: ' . $thefile['error']);
//.........这里部分代码省略.........
开发者ID:oparoz,项目名称:thebuggenie,代码行数:101,代码来源:TBGRequest.class.php

示例2: __

?>
">
			<input type="hidden" name ="MAX_FILE_SIZE" value="<?php 
echo TBGSettings::getUploadsEffectiveMaxSize(true);
?>
">
			<input type="hidden" name="APC_UPLOAD_PROGRESS" value="" />
			<div>
				<dl>
					<dt style="width: 120px;"><label for="uploader_file"><?php 
echo __('Select a file');
?>
</label></dt>
					<dd style="margin-bottom: 3px;"><input type="file" name="uploader_file" id="uploader_file"></dd>
					<?php 
$max_filesize = TBGSettings::getUploadsEffectiveMaxSize();
if ($max_filesize != 0) {
    ?>
					<dt style="width: 100%;"><?php 
    echo __('Files bigger than %max_filesize can not be attached. Please check that the file you are attaching is not bigger than this.', array('%max_filesize' => '<b>' . $max_filesize . 'MB</b>'));
    ?>
</dt>
					<?php 
}
?>
					<dt style="width: 120px;"><label for="upload_file_description"><?php 
echo __('Describe the file');
?>
</label></dt>
					<dd style="margin-bottom: 3px;"><input type="text" name="uploader_file_description" id="upload_file_description" style="width: 440px;"
					placeholder="<?php 
开发者ID:oparoz,项目名称:thebuggenie,代码行数:31,代码来源:_standarduploader.inc.php


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