报错,不知问题在哪。?

报错,不知问题在哪。?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?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(){
         
    }
}

http://img1.sycdn.imooc.com//climg/5c0e42800001222106380174.jpg

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
好帮手慕查理 2018-12-10 18:47:38

您好,报错提示为语法致命错误:重复命名的变量$file_size。请检测下是否重复命名$file_size变量。祝学习愉快!

  • 提问者 初见若安 #1
    就是检查了,没有重复命名啊,所以才上来求助啊。
    2018-12-10 18:59:08
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师
插入代码