代码拉取完成,页面将自动刷新
<?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);
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。