报错,不知问题在哪。?
<?php
class fileUpload
{
const UPLOAD_ERR = [
UPLOAD_ERR_INI_SIZE=>'上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值。',
UPLOAD_ERR_FORM_SIZE=>'上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值。',
UPLOAD_ERR_PARTIAL=>'文件只有部分被上传。',
UPLOAD_ERR_NO_FILE=>'没有文件被上传。',
UPLOAD_ERR_NO_TMP_DIR=>'找不到临时文件夹。',
UPLOAD_ERR_CANT_WRITE=>'文件写入失败。'
];
protected $file_name;
protected $file_path;
protected $file_ext;
protected $file_size;
protected $fileAccName;
protected $file_type;
protected $file_tmp_name;
protected $file_error;
protected $file_acq_size;
protected $errors[];
protected $acqu_ext;
//默认目录为image 默认格式为jpg/png/jpeg/gif ,默认大小为2mb
function __construct($fileName,$filePath="image",$fileExt=['jpg','png','jpeg','gif'],$fileSize = 2097152)
{ //文件名 文件存放目录 文件指定格式 文件大小
$this->file_name = $fileName;
$this->file_path = $filePath;
$this->file_ext = $fileExt;
$this->file_size = $fileSize;
}
//设置图片存放路径
public function setFilePath($filePath){
$this->file_path = $filePath;
}
//设置文件格式
public function setFileExt($fileExt){
$this->file_ext = $fileExt;
}
//设置文件大小
public function setFileSize($fileSize){
$this->file_size = $fileSize;
}
//上传文件
public function upload(){
//接收数据
$this->acceptInfo();
//检查错误
$this->checkError();
//检查格式
$this->checkExt();
//检查大小
$this->checkSize();
//生成新名称
//移动文件
}
protected function acceptInfo(){
$this->fileAccName = $_FILES[$this->file_name]['name'];
$this->file_type = $_FILES[$this->file_name]['type'];
$this->file_tmp_name = $_FILES[$this->file_name]['tmp_name'];
$this->file_error = $_FILES[$this->file_name]['error'];
$this->file_acq_size = $_FILES[$this->file_name]['size'];
}
public function setError($error){
$this->errors[] = $error;
}
protected function checkError(){
if ($this->file_error > UPLOAD_ERR_OK) {
switch ($this->file_error) {
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
case UPLOAD_ERR_PARTIAL:
case UPLOAD_ERR_NO_FILE:
case UPLOAD_ERR_NO_TMP_DIR:
case UPLOAD_ERR_CANT_WRITE:
$this->setError(self::UPLOAD_ERR[$this->file_error]);
break;
}
}
}
protected function checkExt(){
//获取后缀
$this->acqu_ext = pathinfo($this->fileAccName,PATHINFO_EXTENSION);
if (!in_array($this->acqu_ext, $this->file_ext)) {
echo "<script>alert('请上传为图片格式的文件,常见的图片格式有png、jpg、gif');</script>";
exit();
}
}
protected function checkSize(){
}
}
4
收起
正在回答 回答被采纳积分+1
PHP常用技术与ThinkPHP5框架开发
- 参与学习 人
- 提交作业 225 份
- 解答问题 3372 个
掌握用PHP开发互联网网站的必备功能,掌握当下主流的Linux系统开发,并熟练使用热门框架ThinkPhp开发电商团购项目,是通向PHP工程师必经之路。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星