Uploadify.php
2.75 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
namespace app\home\controller;
use qcloudcos\Conf;
use qcloudcos\Myqcloudcos;
class Uploadify extends Base {
public function upload(){
$func = I('func');
$path = I('path','temp');
$info = array(
'num'=> I('num'),
'title' => '',
'upload' =>U('Admin/Ueditor/imageUp',array('savepath'=>$path,'pictitle'=>'banner','dir'=>'logo')),
'size' => '4M',
'type' =>'jpg,png,gif,jpeg',
'input' => I('input'),
'func' => empty($func) ? 'undefined' : $func,
);
$this->assign('info',$info);
return $this->fetch();
}
//营业执照图片上传
public function upload_pic()
{
vendor('qcloudcos.myqcloudcos');
$getoldimg=I('oldimg');
if ((($_FILES["uploadImage"]["type"] == "image/gif")
|| ($_FILES["uploadImage"]["type"] == "image/jpeg")
|| ($_FILES["uploadImage"]["type"] == "image/bmp")
|| ($_FILES["uploadImage"]["type"] == "image/pjpeg")
|| ($_FILES["uploadImage"]["type"] == "image/png"))
){//100KB
$extend = explode(".",$_FILES["uploadImage"]["name"]);
$key = count($extend)-1;
$ext = ".".$extend[$key];
$newfile = md5(mt_rand()).$ext;
if ($getoldimg) //删除旧图
{
$delres=Myqcloudcos::delFile('wxd',$getoldimg);
}
if(!file_exists('public/upload/licenseimg')){mkdir('public/upload/licenseimg');}
move_uploaded_file($_FILES["uploadImage"]["tmp_name"],"public/upload/licenseimg/" . $newfile);
@unlink($_FILES['uploadImage']);
$upimg="/public/upload/licenseimg/";
//保存到存储云
$resfolder=Myqcloudcos::statFolder('wxd',$upimg);
if ($resfolder && $resfolder['code']!=0)//不存在创建
{
Myqcloudcos::createFolder('wxd',$upimg);
}
//上传到腾讯云
$localpath=ROOT_PATH.$upimg.$newfile;
$ypath=$upimg.$newfile;
$res=Myqcloudcos::upload('wxd',$localpath,$ypath);
if($res && $res['code']==0){
mdelFile($localpath);
}
return $upimg.$newfile;
}else {
return 'error';
}
}
/*
删除上传的图片
*/
public function delupload(){
$action=isset($_GET['action']) ? $_GET['action'] : null;
$filename= isset($_GET['filename']) ? $_GET['filename'] : null;
$filename= str_replace('../','',$filename);
$filename= trim($filename,'.');
$filename= trim($filename,'/');
if($action=='del' && !empty($filename)){
$size = getimagesize($filename);
$filetype = explode('/',$size['mime']);
if($filetype[0]!='image'){
return false;
exit;
}
unlink($filename);
exit;
}
}
}