Skip to content

Commit 8a8093f

Browse files
committed
上传网站文件
第一版本
1 parent cd92c80 commit 8a8093f

File tree

2,174 files changed

+338031
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,174 files changed

+338031
-1
lines changed

.gitattributes

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto
3+
4+
# Custom for Visual Studio
5+
*.cs diff=csharp
6+
7+
# Standard to msysgit
8+
*.doc diff=astextplain
9+
*.DOC diff=astextplain
10+
*.docx diff=astextplain
11+
*.DOCX diff=astextplain
12+
*.dot diff=astextplain
13+
*.DOT diff=astextplain
14+
*.pdf diff=astextplain
15+
*.PDF diff=astextplain
16+
*.rtf diff=astextplain
17+
*.RTF diff=astextplain

.gitignore

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Windows image file caches
2+
Thumbs.db
3+
ehthumbs.db
4+
5+
# Folder config file
6+
Desktop.ini
7+
8+
# Recycle Bin used on file shares
9+
$RECYCLE.BIN/
10+
11+
# Windows Installer files
12+
*.cab
13+
*.msi
14+
*.msm
15+
*.msp
16+
17+
# Windows shortcuts
18+
*.lnk
19+
20+
# =========================
21+
# Operating System Files
22+
# =========================
23+
24+
# OSX
25+
# =========================
26+
27+
.DS_Store
28+
.AppleDouble
29+
.LSOverride
30+
31+
# Thumbnails
32+
._*
33+
34+
# Files that might appear on external disk
35+
.Spotlight-V100
36+
.Trashes
37+
38+
# Directories potentially created on remote AFP share
39+
.AppleDB
40+
.AppleDesktop
41+
Network Trash Folder
42+
Temporary Items
43+
.apdisk

.htaccess

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<IfModule mod_rewrite.c>
2+
Options +FollowSymlinks
3+
RewriteEngine On
4+
5+
RewriteCond %{REQUEST_FILENAME} !-d
6+
RewriteCond %{REQUEST_FILENAME} !-f
7+
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
8+
</IfModule>

.idea/.name

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/scopes/scope_settings.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 1052 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/yershop.iml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php
2+
// +----------------------------------------------------------------------
3+
// | OneThink [ WE CAN DO IT JUST THINK IT ]
4+
// +----------------------------------------------------------------------
5+
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
6+
// +----------------------------------------------------------------------
7+
// | Author: 麦当苗儿 <[email protected]> <http://www.zjzit.cn>
8+
// +----------------------------------------------------------------------
9+
10+
namespace Addons\Attachment;
11+
use Common\Controller\Addon;
12+
13+
/**
14+
* 附件插件
15+
* @author 麦当苗儿 <[email protected]>
16+
*/
17+
class AttachmentAddon extends Addon{
18+
19+
public $info = array(
20+
'name' => 'Attachment',
21+
'title' => '附件',
22+
'description' => '用于文档模型上传附件',
23+
'status' => 1,
24+
'author' => 'thinkphp',
25+
'version' => '0.1'
26+
);
27+
28+
public $admin_list = array(
29+
'list_grid' => array(
30+
'id:ID',
31+
'title:文件名',
32+
'size:大小',
33+
'update_time_text:更新时间',
34+
'document_title:文档标题'
35+
),
36+
'model'=>'Attachment',
37+
'order'=>'id asc'
38+
);
39+
40+
public $custom_adminlist = 'adminlist.html';
41+
42+
public function install(){
43+
return true;
44+
}
45+
46+
public function uninstall(){
47+
return true;
48+
}
49+
50+
/* 显示文档模型编辑页插件扩展信息表单 */
51+
public function documentEditForm($param = array()){
52+
$this->assign($param);
53+
$this->display(T('Addons://Attachment@Article/edit'));
54+
}
55+
56+
/* 文档末尾显示附件列表 */
57+
public function documentDetailAfter($info = array()){
58+
if(empty($info) || empty($info['id'])){ //数据不正确
59+
return ;
60+
}
61+
62+
/* 获取当前文档附件 */
63+
$Attachment = D('Addons://Attachment/Attachment');
64+
$map = array('record_id' => $info['id'], 'status' => 1);
65+
$list = $Attachment->field(true)->where($map)->select();
66+
if(!$list){ //不存在附件
67+
return ;
68+
}
69+
70+
/* 模板赋值并渲染模板 */
71+
$this->assign('list', $list);
72+
$this->display(T('Addons://Attachment@Article/detail'));
73+
}
74+
75+
/**
76+
* 文档保存成功后执行行为
77+
* @param array $data 文档数据
78+
* @param array $catecory 分类数据
79+
*/
80+
public function documentSaveComplete($param){
81+
if (MODULE_NAME == 'Home') {
82+
list($data, $category) = $param;
83+
/* 附件默认配置项 */
84+
$default = C('ATTACHMENT_DEFAULT');
85+
86+
/* 合并当前配置 */
87+
$config = $category['extend']['attachment'];
88+
$config = empty($config) ? $default : array_merge($default, $config);
89+
$attach = I('post.attachment');
90+
91+
/* 该分类不允许上传附件 */
92+
if(!$config['is_upload'] || !in_array($attach['type'], str2arr($config['allow_type']))){
93+
return ;
94+
}
95+
96+
switch ($attach['type']) {
97+
case 1: //外链
98+
# code...
99+
break;
100+
case 2: //文件
101+
$info = json_decode(think_decrypt($attach['info']), true);
102+
if(!empty($info)){
103+
$Attachment = D('Addons://Attachment/Attachment');
104+
$Attachment->saveFile($info['name'], $info, $data['id']);
105+
} else {
106+
return; //TODO:非法附件上传,可记录日志
107+
}
108+
break;
109+
}
110+
}
111+
}
112+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
// +----------------------------------------------------------------------
3+
// | OneThink [ WE CAN DO IT JUST THINK IT ]
4+
// +----------------------------------------------------------------------
5+
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
6+
// +----------------------------------------------------------------------
7+
// | Author: 麦当苗儿 <[email protected]> <http://www.zjzit.cn>
8+
// +----------------------------------------------------------------------
9+
10+
namespace Addons\Attachment\Controller;
11+
use Home\Controller\AddonsController;
12+
13+
class AttachmentController extends AddonsController{
14+
15+
/* 附件下载 */
16+
public function download(){
17+
/* 获取附件ID */
18+
$id = I('get.id');
19+
if(empty($id) || !is_numeric($id)){
20+
$this->error('附件ID无效!');
21+
}
22+
23+
/* 下载附件 */
24+
$Attachment = D('Addons://Attachment/Attachment');
25+
if(false === $Attachment->download($id)){
26+
$this->error($Attachment->getError());
27+
}
28+
29+
}
30+
31+
/* 上传附件 */
32+
public function upload(){
33+
/* 返回标准数据 */
34+
$return = array('status' => 1, 'info' => '上传成功', 'data' => '');
35+
36+
/* 获取当前分类附件配置信息 */
37+
$default = C('ATTACHMENT_DEFAULT');
38+
$category = get_category(I('get.category'));
39+
40+
/* 分类正确性检测 */
41+
if(empty($category)){
42+
$return['status'] = 0;
43+
$return['info'] = '没有指定分类或分类不正确;';
44+
} else {
45+
$config = $category['extend']['attachment'];
46+
$config = empty($config) ? $default : array_merge($default, $config);
47+
48+
/* 检测并上传附件 */
49+
if(in_array('2', str2arr($config['allow_type']))){
50+
$setting = C('ATTACHMENT_UPLOAD');
51+
52+
/* 调用文件上传组件上传文件 */
53+
$File = D('File');
54+
$info = $File->upload($_FILES, $setting, $config['driver'], $config['driver_config']);
55+
/* 记录附件信息 */
56+
if($info){
57+
$return['data'] = think_encrypt(json_encode($info['attachment']));
58+
} else {
59+
$return['status'] = 0;
60+
$return['info'] = $File->getError();
61+
}
62+
} else {
63+
$return['info'] = '该分类不允许上传文件附件!';
64+
$return['status'] = 0;
65+
}
66+
}
67+
68+
/* 返回JSON数据 */
69+
$this->ajaxReturn($return);
70+
}
71+
72+
}

0 commit comments

Comments
 (0)