-
Notifications
You must be signed in to change notification settings - Fork 0
/
uploadimg.php
62 lines (57 loc) · 1.6 KB
/
uploadimg.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/*
* 上传图片插件
@ return array('error'=>,'url'=>)
@ yuanjiang 9.5.2013
*/
define("IN_BS",true);
require('includes/init.php');
require('includes/cls_image.php');
/* 定义操作 */
$act = isset($_REQUEST['act']) ? $Common->charFormat($_REQUEST['act']) : false ;
/* 未上传文件 */
if(empty($_FILES)===true)
{
die('hacking attempt');
}
/*
======================================= 具体操作 ===============================================
*/
$dir_name = '/images/';
$picSize = $_FILES['imgFile']['size']; //图片尺寸
list($picWidth, $picHeight) = getimagesize($_FILES['imgFile']['tmp_name']); //图片高宽
/* 通知详情的图片 */
if($act=='notice' || $act=='intro' || $act=='info' || $act=='lifenav' || $act=='redpacket')
{
$maxSize = 1*1024*1024 ;
$dir_name .= $act ;
if($picSize>$maxSize) // 检查图片大小
{
$msg['error'] = 1;
$msg['message'] = '上传图片不能大于1M' ;
}
else
{
$cls_image = new cls_image('#ffffff',$dir_name);
$upload = isset($_FILES['imgFile']) ? $_FILES['imgFile'] : '' ;
$msg = $cls_image-> upload_image($upload, $dir = '', $img_name = '');
if($msg['error']==0)
{
$msg['url'] = $msg['msg'];
if($picWidth>640) //上传图片超过640px,则生成缩略图
{
$msg['msg'] = substr($msg['msg'],1);
$msg['url'] = $cls_image->make_thumb($msg['msg'],$width=640,$height=0,$path='',$pic='');
@unlink($msg['msg']); // 删除原图,只保留缩略图
}
}
else
{
$msg['message'] = $msg['msg'];
}
}
}
$msg = $Json->encode($msg);
echo $msg;
exit;
?>