会员登录 | 会员注册 | 意见建议 | 网站地图

站长资源综合门户

当前位置:首页 > 站长学院 > 编程程序 > PHP非常实用的上传类,上传效果在线演示

PHP非常实用的上传类,上传效果在线演示

时间:2012-08-11 17:34:09   作者:   来源:   点击:

 

#*********************************************************

#文件名称:

inc_class.upload.php

#Copyright (c)

2007-2009 青春一度 all rights reserved.

#最后更新: 2009-08-05

#版本 : v 2.0.a

#注:转发时请保留此声明信息,这段声明不并会影响你的速度!

#如有修改请将修改后的文件以邮件形式发送给作者一份,谢谢!

#

#*********************************************************

if(!defined('IN_PHPADLEYIU'))

{

exit('Access Denied');

}

/*

//使用说明:

//声明一个上传类

include_once(ADLEYLIU_ROOT.'./inc_class.upload.php');

$_YL_UPLOAD

= array();

$yl_uploadfile = new

yl_upload_class();

$_YL_UPLOAD['yl_filedata'] =

'uploadFile';//表单名

$_YL_UPLOAD['yl_directroy'] =

'upload_files';//上传主目录

$_YL_UPLOAD['file_urldirectroy'] = '/';//

程序路径

$_YL_UPLOAD['yl_settingsnew'] =

''('ym').'/'('d').'/'.substr(time(), 0,

5).'';//上传子主目录

$_YL_UPLOAD['yl_maxsize'] = 1048576;

//这里以字节为单位(1024*2)*1024=2097152 就是 2M

$_YL_UPLOAD['yl_sizeformat'] =

'k'; //显示文件大小单位b字节,k千,m兆

$_YL_UPLOAD['yl_arrext'] =

array('gif','jpg','jpeg','png','bmp','rar','txt');//允许上传文件类型

$_YL_UPLOAD['yl_ext'] = 0; //0原文件类型上传,1统一为存为jpg

$_YL_UPLOAD['yl_prefix'] = ''.$uid.''.$yl_uploadfile -> yl_createrand(1,0).''.$cid.'';

//在文件名前缀加上特殊字符 //$uid 会员ID $cid 分类ID

$_YL_UPLOAD['yl_suffix'] = ''; //''.$yl_uploadfile -> yl_createrand(3,0).'';

//在文件名后缀加上特殊字符

$_YL_UPLOAD['thumbwidth'] = 100;

//缩略图宽

$_YL_UPLOAD['thumbheight'] = 100;

//缩略图高

$_YL_UPLOAD['maxthumbwidth'] = 500;

//大图高

$_YL_UPLOAD['maxthumbheight'] = 500;

//大图宽

//上传

$yl_uploadfile -> yl_uploadfile();

获取值:

'yl_filename' => addslashes($_YL_UPLOAD['yl_filename']),原文件名

'yl_attachment' => $_YL_UPLOAD['yl_attachment'],新文件名及路径

'yl_filesize' => $_YL_UPLOAD['yl_filesize'] ,文件大小

'yl_filetype' => $_YL_UPLOAD['yl_filetype'],文件类型

'yl_isimage' => $_YL_UPLOAD['yl_isimage'],是否是图片

'yl_isthumb' => $_YL_UPLOAD['yl_isthumb'],是否有小图片

*/

class yl_upload_class

{

function __GET($property_name)

{

if(isset($this -> $property_name))

{

return $this -> $property_name;

} else

{

return

NULL;

}

}

function __SET($property_name,

$value) {

$this -> $property_name =

$value;

}

#*********************************************************

#生成缩略图

#*********************************************************

function makethumb($srcfile) {

global $_YL_UPLOAD;

//判断文件是否存在

if (!file_exists($srcfile))

{

return '';

}

$dstfile =

$srcfile.'.small.jpg';

$bigfile =

$srcfile.'.big.jpg';

//缩略图大小

$tow =

intval($_YL_UPLOAD['thumbwidth']);

$toh =

intval($_YL_UPLOAD['thumbheight']);

if($tow < 60) $tow =

60;

if($toh < 60) $toh = 60;

$make_max = 0;

$maxtow =

intval($_YL_UPLOAD['maxthumbwidth']);

$maxtoh =

intval($_YL_UPLOAD['maxthumbheight']);

if($maxtow >= 300

&& $maxtoh >= 300) {

$make_max =

1;

}

//获取图片信息

$im = '';

if($data =

getimagesize($srcfile)) {

if($data[2] == 1)

{

$make_max =

0;//gif不处理

if(function_exists("imagecreatefromgif"))

{

$im =

imagecreatefromgif($srcfile);

}

}

elseif($data[2] == 2)

{

if(function_exists("imagecreatefromjpeg"))

{

$im =

imagecreatefromjpeg($srcfile);

}

}

elseif($data[2] == 3)

{

if(function_exists("imagecreatefrompng"))

{

$im =

imagecreatefrompng($srcfile);

}

}

}

if(!$im)

return '';

$srcw = imagesx($im);

$srch = imagesy($im);

分享到:

网友评论

热门编程程序