Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (3)
Tags (6)
master
Invite_register
role
0.7.0
0.6.0
beta2
dd
1.0beta
0.1开发版
master
Branches (3)
Tags (6)
master
Invite_register
role
0.7.0
0.6.0
beta2
dd
1.0beta
0.1开发版
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (3)
Tags (6)
master
Invite_register
role
0.7.0
0.6.0
beta2
dd
1.0beta
0.1开发版
OpenCenter
/
Application
/
Home
/
Model
/
FileModel.class.php
OpenCenter
/
Application
/
Home
/
Model
/
FileModel.class.php
FileModel.class.php 4.29 KB
Copy Edit Raw Blame History
想天皮克斯 authored 2015年01月08日 15:37 +08:00 . 初始化
<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------
namespace Home\Model;
use Think\Model;
/**
* 文件模型
* 负责文件的下载和上传
*/
class FileModel extends Model{
/**
* 文件模型自动完成
* @var array
*/
protected $_auto = array(
array('create_time', NOW_TIME, self::MODEL_INSERT),
);
/**
* 文件模型字段映射
* @var array
*/
protected $_map = array(
'type' => 'mime',
);
/**
* 文件上传
* @param array $files 要上传的文件列表(通常是$_FILES数组)
* @param array $setting 文件上传配置
* @param string $driver 上传驱动名称
* @param array $config 上传驱动配置
* @return array 文件上传成功后的信息
*/
public function upload($files, $setting, $driver = 'Local', $config = null){
/* 上传文件 */
$setting['callback'] = array($this, 'isFile');
$Upload = new \Think\Upload($setting, $driver, $config);
$info = $Upload->upload($files);
/* 设置文件保存位置 */
$this->_auto[] = array('location', 'Ftp' === $driver ? 1 : 0, self::MODEL_INSERT);
if($info){ //文件上传成功,记录文件信息
foreach ($info as $key => &$value) {
/* 已经存在文件记录 */
if(isset($value['id']) && is_numeric($value['id'])){
continue;
}
/* 记录文件信息 */
if($this->create($value) && ($id = $this->add())){
$value['id'] = $id;
} else {
//TODO: 文件上传成功,但是记录文件信息失败,需记录日志
unset($info[$key]);
}
}
return $info; //文件上传成功
} else {
$this->error = $Upload->getError();
return false;
}
}
/**
* 下载指定文件
* @param number $root 文件存储根目录
* @param integer $id 文件ID
* @param string $args 回调函数参数
* @return boolean false-下载失败,否则输出下载文件
*/
public function download($root, $id, $callback = null, $args = null){
/* 获取下载文件信息 */
$file = $this->find($id);
if(!$file){
$this->error = '不存在该文件!';
return false;
}
/* 下载文件 */
switch ($file['location']) {
case 0: //下载本地文件
$file['rootpath'] = $root;
return $this->downLocalFile($file, $callback, $args);
case 1: //TODO: 下载远程FTP文件
break;
default:
$this->error = '不支持的文件存储类型!';
return false;
}
}
/**
* 检测当前上传的文件是否已经存在
* @param array $file 文件上传数组
* @return boolean 文件信息, false - 不存在该文件
*/
public function isFile($file){
if(empty($file['md5'])){
throw new Exception('缺少参数:md5');
}
/* 查找文件 */
$map = array('md5' => $file['md5']);
return $this->field(true)->where($map)->find();
}
/**
* 下载本地文件
* @param array $file 文件信息数组
* @param callable $callback 下载回调函数,一般用于增加下载次数
* @param string $args 回调函数参数
* @return boolean 下载失败返回false
*/
private function downLocalFile($file, $callback = null, $args = null){
if(is_file($file['rootpath'].$file['savepath'].$file['savename'])){
/* 调用回调函数新增下载数 */
is_callable($callback) && call_user_func($callback, $args);
/* 执行下载 */ //TODO: 大文件断点续传
header("Content-Description: File Transfer");
header('Content-type: ' . $file['type']);
header('Content-Length:' . $file['size']);
if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) { //for IE
header('Content-Disposition: attachment; filename="' . rawurlencode($file['name']) . '"');
} else {
header('Content-Disposition: attachment; filename="' . $file['name'] . '"');
}
readfile($file['rootpath'].$file['savepath'].$file['savename']);
exit;
} else {
$this->error = '文件已被删除!';
return false;
}
}
}
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

基于Apache2.0 开源通用 用户及后台管理框架,提供了注册登录、头像裁剪、单点登录、权限管理、扩展资料管理、等级头衔、自定义积分管理、用户行为日志机制、模块装卸、插件机制,提供建议的安装程序。适合需要开发全新的PHP系统。有需要的朋友可以自行下载研究。目前为开发版。项目主页www.ocenter.cn 开发者讨论区 dev.ocenter.cn 项目演示站 demo.ocenter.cn 在线开发手册http://www.ocenter.cn/index.php?m=book&f=browse&nodeID=1
Cancel

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/case-code/OpenCenter.git
git@gitee.com:case-code/OpenCenter.git
case-code
OpenCenter
OpenCenter
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /