文件上传不适用于oops PHP

时间:2016-09-26 07:35:27

标签: php oop

public function upload($file = array(), $where) 
{
    if (file_exists($this->src.$file['name']))
    {
        $data['error'] = "Sorry, file already exists.";
    }
    elseif ($file["name"]["size"] > 500000) {
        $data['error'] = "Sorry, your file is too large.";
    }
    elseif(is_array($file))
    {
        if(in_array($file['type'], $this->type))
        {
            $filePath = $this->src.$file['name'];
            $file_Check = move_uploaded_file($file['name']['tmp_name'], $filePath);
            if ($file_Check)
            {
                print_r($file); die(); 
                $name = $file['name'];
                //$this->update(array('photo'=>$name,'candi_id'=>$where));
            }               
            $data['error'] = 'File has been uploaded';
        }
        else
        {
            $data['error'] = 'File formet was not supported';
        }
    }
    else
    {
        $data['error'] = 'No File was uploaded...';         
    }

    return $data;       
}

输出:

文件路径显示正确。功能也工作正常,但文件没有移动到文件夹?

1 个答案:

答案 0 :(得分:0)

将<{1}}添加到表单中,例如

enctype="multipart/form-data"