<?php
//====================================================
// FileName:upload.inc.php
// Summary: 上传类
// Author: Space.As
// CreateTime:20090323
// LastModifed:20090323
// copyright e000s#php
//====================================================
define('E000S', TRUE);
/*********************************************************************
* sa_upload(FormName, Directroy, MaxSize); 实例化上传类
* FormName 文件域名称
* Directroy 指定上传路径
* MaxSize 设置可上传文件大小
*
* 调用方法
* upload(fileName);文件上传,强制命名fileName
* cut_upload(fileName, Width, Height);裁剪上传,强制命名fileName,尺寸
* thumb(dscChar, Width, Height);创建缩略图,前缀,尺寸
* filePath();文件路径
* thumbMap();缩略图路径
* get_Time();上传时间
*
* 错误代码
* 错误参数:
* 0=正常,
* 1=文件域未定义,
* 2=文件不存在或者无法读取,
* 3=上传失败目录不可写?
* 4=无法执行裁剪上传(文件格式不支持?),
* 6=未知错误!,
* 7=无法创建缩略图(文件格式不支持?),
*********************************************************************/
class sa_upload{
var $FormName; //文件域名称
var $Directroy; //上传至目录
var $MaxSize; //最大上传大小
var $CanUpload; //是否可以上传
var $doUpFile; //上传的文件名
var $sm_File; //缩略图名称
var $a_Time;//附件上传时间
var $Error;
//构造函数
function sa_upload($formName='', $dirPath='', $maxSize=8) //formName=文件域,dirPath=上传目录,maxSize=上传大小限制
{
//初始化各种参数
$this->FormName = $formName;
$this->MaxSize = $maxSize;
$this->CanUpload = true;
$this->doUpFile = '';
$this->sm_File = '';
$this->Error = 0;
//文件域检测
if ($formName == ''){
$this->CanUpload = false;
$this->Error = 1;
break;
}
//上传路径处理
if ($dirPath == ''){
$this->Directroy = $dirPath;
}else{
$this->Directroy = $dirPath.'/';
}
//文件大小检测
if($this->getSize(M) > $this->MaxSize){
$this->CanUpload = false;
$this->Error = 7;
return $this->Error;
break;
}
}
//检查文件是否存在
function scanFile()
{
if ($this->CanUpload){
$scan = is_readable($_FILES[$this->FormName]['name']);
if ($scan){
$this->Error = 2;
}
return $this->scan;
}
}
//获取文件大小
function getSize($format = 'B')
{
if ($this->CanUpload){
if ($_FILES[$this->FormName]['size'] == 0){
$this->Error = 2;
$this->CanUpload = false;
}
//计算文件大小
switch ($format){
case 'B':
return $_FILES[$this->FormName]['size'].'kb';
break;
case 'M':
return sprintf("%01.2f",($_FILES[$this->FormName]['size'])/(1024*1024)).'mb';
}
}
}
//获取文件类型
function getExt()
{
if ($this->CanUpload){
$ext=$_FILES[$this->FormName]['name'];
$extStr=explode('.',$ext);
$count=count($extStr)-1;
}
return $extStr[$count];
}
//获取文件名称
function getName()
{
if ($this->CanUpload){
return $_FILES[$this->FormName]['name'];
}
}
//获取上传时间
function get_Time()
{
if ($this->CanUpload){
return $this->a_Time;
}
}
//重命名
function newName()
{
if ($this->CanUpload){
$FullName=$_FILES[$this->FormName]['name'];
$extStr=explode('.',$FullName);
$count=count($extStr)-1;
$ext = $extStr[$count];
$tempTimes=time();
$this->a_Time=$tempTimes;
return $FullName.'-'.$tempTimes.'.'.$ext;
}
}
//上传文件
function upload($fileName = '')
{
if ($this->CanUpload){
if ($_FILES[$this->FormName]['size'] == 0){
$this->Error = 2;
$this->CanUpload = false;
return $this->Error;
break;
}
}
if($this->CanUpload){
//未指定名称则执行默认重命名
if ($fileName == ''){
$fileName = $this->newName();
}else{
$this->a_Time=time();
$fileName = $fileName.'.'.$this->getExt();
}
//上传
$this->doUpload=@copy($_FILES[$this->FormName]['tmp_name'], $this->Directroy.$fileName);
if($this->doUpload)
{//上传成功则返回重命名之后名称,更改文件属性
$this->doUpFile = $fileName;
chmod($this->Directroy.$fileName, 0777);
return true;
}else{//上传失败,返回错误代码
$this->Error = 3;
return $this->Error;
}
}
}
//裁剪上传
function cut_upload($fileName = '',$width=500,$height=500){
if ($this->CanUpload){
if ($_FILES[$this->FormName]['size'] == 0){
$this->Error = 2;
$this->CanUpload = false;
return $this->Error;
break;
}
}
if($this->CanUpload){
//未指定名称则执行默认重命名
if ($fileName == ''){
$fileName = $this->newName();
}else{
$this->a_Time=time();
$fileName = $fileName.'.'.$this->getExt();
}
//检查是否可自行裁剪操作(图片),特殊原因png不支持裁剪上传
$data = getimagesize($_FILES[$this->FormName]['tmp_name'],&$info);
switch ($data[2]) {
case 1:
$temp_img = @imagecreatefromgif($_FILES[$this->FormName]['tmp_name']);
break;
case 2:
$temp_img = @imagecreatefromjpeg($_FILES[$this->FormName]['tmp_name']);
break;
default:
$this->Error = 4;
$this->CanUpload = false;
return $this->Error;
break;
}
$o_width = imagesx($temp_img); //取得原图宽
$o_height = imagesy($temp_img); //取得原图高
if($width>$o_width && $height>$o_height){//原图小于裁剪尺寸,直接使用原图,并且返回文件名称.
$this->doUpload=@copy($_FILES[$this->FormName]['tmp_name'], $this->Directroy.$fileName);
if($this->doUpload)
{//上传成功则返回重命名之后名称,更改文件属性
$this->doUpFile = $fileName;
chmod($this->Directroy.$fileName, 0777);
return true;
}else{//上传失败,返回错误代码
$this->Error = 3;
return $this->Error;
}
}else{//原图大于裁剪尺寸,执行裁剪
//等比缩放尺寸计算
if($o_width/$o_height >= $width/$height){
if($o_width>$width){
$newwidth=$width;
$newheight=$o_height*$width/$o_width;
}else{
$newwidth=$o_width;
$newheight=$o_height;
}
}else{
if($o_height>$height){
$newheight=$height;
$newwidth=$o_width*$height/$o_height;
}else{
$newwidth=$o_width;
$newheight=$o_height;
}
}
//图片生成
$new_img = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($new_img, $temp_img, 0, 0, 0, 0, $newwidth, $newheight, $o_width, $o_height);
$cr=imagejpeg($new_img , $this->Directroy.$fileName);
$this->doUpFile=$fileName;
imagedestroy($new_img);
//返回执行结果
if ($cr){
$this->sm_File = $dscFile;
return true;
}else{
$this->Error = 15;
return $this->Error;
}
}
}
}
//创建图片缩略图
function thumb($dscChar='',$width=150,$height=113)
{
if ($this->CanUpload && $this->doUpFile != ''){
$srcFile = $this->doUpFile;
//缩略图前缀
if ($dscChar == ''){
$dscChar = 'sm_';
}
$dscFile = $this->Directroy.$dscChar.$srcFile;
$data = getimagesize($this->Directroy.$srcFile,&$info);
switch ($data[2]) {
case 1:
$im = @imagecreatefromgif($this->Directroy.$srcFile);
break;
case 2:
$im = @imagecreatefromjpeg($this->Directroy.$srcFile);
break;
case 3:
$im = @imagecreatefrompng($this->Directr
没有合适的资源?快使用搜索试试~ 我知道了~
PHP实例开发源码—IDE Bee 社会互动营销平台GBK.zip
共1899个文件
png:608个
php:371个
gif:344个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 171 浏览量
2022-11-11
22:54:13
上传
评论
收藏 14.29MB ZIP 举报
温馨提示
PHP实例开发源码—IDE Bee 社会互动营销平台GBK.zip
资源推荐
资源详情
资源评论
收起资源包目录
PHP实例开发源码—IDE Bee 社会互动营销平台GBK.zip (1899个子文件)
JPGEncoder.as 19KB
PNGEncoder.as 5KB
BitString.as 2KB
dialog.css 29KB
module.css 26KB
layout.css 13KB
default.css 8KB
tinymce.css 8KB
calendar.css 6KB
style.css 6KB
style.css 4KB
style.css 4KB
ui.css 4KB
style.css 4KB
style.css 4KB
style.css 4KB
style.css 4KB
style.css 4KB
style.css 4KB
style.css 3KB
style.css 3KB
style.css 3KB
style.css 3KB
style.css 3KB
style.css 3KB
style.css 3KB
style.css 3KB
style.css 3KB
style.css 3KB
style.css 3KB
style.css 3KB
style.css 3KB
style.css 3KB
style.css 3KB
style.css 3KB
style.css 3KB
style.css 3KB
style.css 3KB
ubb.css 2KB
share.css 2KB
install.css 1KB
feed.css 642B
style.css 597B
style.css 589B
style.css 586B
style.css 576B
style.css 575B
style.css 39B
none.cur 2KB
wry.dat 7.58MB
qrv40_2.dat 87KB
qrv40_3.dat 87KB
qrv40_0.dat 87KB
qrv40_1.dat 87KB
qrv39_2.dat 83KB
qrv39_3.dat 83KB
qrv39_0.dat 83KB
qrv39_1.dat 83KB
qrv38_2.dat 79KB
qrv38_3.dat 79KB
qrv38_0.dat 79KB
qrv38_1.dat 79KB
qrv37_2.dat 75KB
qrv37_3.dat 75KB
qrv37_0.dat 75KB
qrv37_1.dat 75KB
qrv36_2.dat 71KB
qrv36_3.dat 71KB
qrv36_0.dat 71KB
qrv36_1.dat 71KB
qrv35_2.dat 67KB
qrv35_3.dat 67KB
qrv35_0.dat 67KB
qrv35_1.dat 67KB
qrv34_2.dat 65KB
qrv34_3.dat 65KB
qrv34_0.dat 65KB
qrv34_1.dat 65KB
qrv33_2.dat 61KB
qrv33_3.dat 61KB
qrv33_0.dat 61KB
qrv33_1.dat 61KB
qrv32_2.dat 58KB
qrv32_3.dat 58KB
qrv32_0.dat 58KB
qrv32_1.dat 58KB
qrv31_2.dat 55KB
qrv31_3.dat 55KB
qrv31_0.dat 55KB
qrv31_1.dat 55KB
qrv30_2.dat 51KB
qrv30_3.dat 51KB
qrv30_0.dat 51KB
qrv30_1.dat 51KB
qrv29_2.dat 48KB
qrv29_3.dat 48KB
qrv29_0.dat 48KB
qrv29_1.dat 48KB
qrv28_2.dat 45KB
qrv28_3.dat 45KB
共 1899 条
- 1
- 2
- 3
- 4
- 5
- 6
- 19
资源评论
毕业_设计
- 粉丝: 1925
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功