uploader.php
来自「php 开发的内容管理系统」· PHP 代码 · 共 172 行
PHP
172 行
<?php
/**
* Article management
*
* @copyright The XOOPS project http://www.xoops.org/
* @license http://www.fsf.org/copyleft/gpl.html GNU public license
* @author Taiwen Jiang (phppp or D.J.) <php_pp@hotmail.com>
* @since 1.00
* @version $Id$
* @package module::article
*/
if (!defined('XOOPS_ROOT_PATH')){ exit(); }
if(defined("art_UPLOADER")) return;
define("art_UPLOADER",1);
require_once(XOOPS_ROOT_PATH . "/class/uploader.php");
if(!class_exists("art_uploader")){
class art_uploader extends XoopsMediaUploader
{
var $ext = "";
var $ImageSizeCheck = false;
var $FileSizeCheck = false;
var $CheckMediaTypeByExt = true;
/**
* No admin check for uploads
*/
/**
* Constructor
*
* @param string $uploadDir
* @param array $allowedMimeTypes
* @param int $maxFileSize
* @param int $maxWidth
* @param int $maxHeight
* @param int $cmodvalue
*/
function art_uploader($uploadDir, $allowedMimeTypes = false, $maxFileSize = 0, $maxWidth = 0, $maxHeight = 0)
{
if (!is_array($allowedMimeTypes)) {
if($allowedMimeTypes == false || $allowedMimeTypes == "*")
$allowedMimeTypes = false;
else{
$allowedMimeTypes = explode("|", strtolower($allowedMimeTypes));
if (in_array("*", $allowedMimeTypes)) {
$allowedMimeTypes = false;
}
}
}
$this->XoopsMediaUploader($uploadDir, $allowedMimeTypes, $maxFileSize, $maxWidth, $maxHeight);
//$this->setTargetFileName($this->getMediaName());
}
/**
* Set the CheckMediaTypeByExt
*
* @param string $value
*/
function setCheckMediaTypeByExt($value = true)
{
$this->CheckMediaTypeByExt = $value;
}
/**
* Set the imageSizeCheck
*
* @param string $value
*/
function setImageSizeCheck($value)
{
$this->ImageSizeCheck = $value;
}
/**
* Set the fileSizeCheck
*
* @param string $value
*/
function setFileSizeCheck($value)
{
$this->FileSizeCheck = $value;
}
/**
* Get the file extension
*
* @return string
*/
function getExt()
{
$this->ext = strtolower(ltrim(strrchr($this->getMediaName(), '.'), '.'));
return $this->ext;
}
/**
* Is the file the right size?
*
* @return bool
*/
function checkMaxFileSize()
{
if (!$this->FileSizeCheck) {
return true;
}
if ($this->mediaSize > $this->maxFileSize) {
return false;
}
return true;
}
/**
* Is the picture the right width?
*
* @return bool
*/
function checkMaxWidth()
{
if (!$this->ImageSizeCheck) {
return true;
}
if (false !== $dimension = getimagesize($this->mediaTmpName)) {
if ($dimension[0] > $this->maxWidth) {
return false;
}
} else {
trigger_error(sprintf('Failed fetching image size of %s, skipping max width check..', $this->mediaTmpName), E_USER_WARNING);
}
return true;
}
/**
* Is the picture the right height?
*
* @return bool
*/
function checkMaxHeight()
{
if (!$this->ImageSizeCheck) {
return true;
}
if (false !== $dimension = getimagesize($this->mediaTmpName)) {
if ($dimension[1] > $this->maxHeight) {
return false;
}
} else {
trigger_error(sprintf('Failed fetching image size of %s, skipping max height check..', $this->mediaTmpName), E_USER_WARNING);
}
return true;
}
/**
* Is the file the right Mime type
*
* (is there a right type of mime? ;-)
*
* @return bool
*/
function checkMimeType()
{
if ($this->CheckMediaTypeByExt) $type = $this->getExt();
else $type = $this->mediaType;
if (count($this->allowedMimeTypes) > 0 && !in_array($type, $this->allowedMimeTypes)) {
return false;
}
return true;
}
}
}
?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?