我在 CodeIgniter 中上传文件时遇到问题。这是我的自动加载:$autoload['helper'] = array('url', 'form', 'file');
我已经回应了realpath(APPPATH . '../images');
,这是正确的位置。当我点击提交时,什么也没有发生,也没有显示错误;它只是重新加载视图。
模型:
<?php
class Gallery_model extends CI_Model{
var $gallery_path;
function __construct()
{
parent::__construct();
$this->gallery_path = realpath(APPPATH . '../images');
}
function do_upload()
{
//handle userfile
$config = array(
'allowed_types' => 'jpg|jpeg|gif|png',
'upload_path' => $this->gallery_path
);
$this->load->library('upload', $config);
$this->upload->do_upload();
}
}
?>
控制器:
<?php
class Gallery extends CI_Controller
{
function index()
{
$this->load->model('Gallery_model');
if($this->input->post('upload'))
{
//handle upload
$this->Gallery_model->do_upload();
}
$this->load->view('gallery');
}
}
?>
看法:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Gallery</title>
</head>
<body>
<div id="gallery">
</div>
<div id="upload">
<?php
echo form_open_multipart('gallery');
echo form_upload('userfile');
echo form_submit('upload', 'Upload');
echo form_close();
?>
</div>
</body>
</html>
问题是什么?