1 Star 0 Fork 0

菜鸟中的战斗机 / StudyClass

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Upload.class.php 1.45 KB
一键复制 编辑 原始数据 按行查看 历史
菜鸟中的战斗机 提交于 2016-07-21 18:14 . add upload
<?php
class Upload{
private $config = array(
'maxSiez' => 0, //上传文件最大大小 0 不限大小
'exts' => array(), //允许上传文件后缀
'rootPath' => './Uploads' //上传文件根目录
);
private $error = ''; //保存错误信息
public function __construct($config = array()){
//初始化配置项
$this->config = array_merge($this->config,$config);
if (!empty($this->config['exts'])) {
//如果是字符串类型则转换成数组
if (is_string($this->config['exts'])) {
$this->config['exts'] = explode(',',$this->config['exts']);
}
//将字符全部小写
$this->config['exts'] = array_map('strtolower',$this->config['exts']);
}
}
public function upload () {
$files = $_FILES;
//检查文件夹
if (!$this->checkRootPath()) {
$this->error='您上传目录'.$this->config['rootPath'].'不存在,请尝试手动创建';
return false;
}
if (empty($files)) {
$this->error = '没有上传文件';
return false;
}
}
/**
* [checkRootPath 检查文件夹是否存在]
* @return [bool] [description]
*/
private function checkRootPath () {
if (!file_exists($this->config['rootPath'])) {
return $this->mkdir($this->config['rootPath']));
}
return true;
}
/**
* [mkdir 创建目录]
* @param [string] $file [要创建的文件夹]
* @return [bool] [description]
*/
private function mkdir ($file) {
return mkdir($file,0777,true);
}
}
PHP
1
https://gitee.com/aiqbc/StudyClass.git
git@gitee.com:aiqbc/StudyClass.git
aiqbc
StudyClass
StudyClass
master

搜索帮助