我的codeigniter上传表格有问题
View.php我在Codeigniter文档中找到了这段代码,我不知道问题出在哪里..
<?php echo $error;?>
<?php echo form_open_multipart('upload/do_upload');?>
<input type="file" name="userfile" size="20" />
<br /><br />
<input type="submit" value="upload" />
</form>
upload.php就是upload.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Upload extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
}
function index()
{
$this->load->view('upload_form', array('error' => ' ' ));
}
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
}
?>
当我上传一些图片ci给我
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Upload::$upload
Filename: controllers/Upload.php
Line Number: 52
Backtrace:
Fatal error: Call to a member function do_upload() on a non-object in
问题出在哪里?谢谢
答案 0 :(得分:0)
修改强>
从您发布的链接中,我按照上传文件的指南进行操作,并且完美无缺。
确保正确设置CI:
必须将文件夹application
和system
以及文件index.php
上传到您正常工作的网络服务器,然后您必须创建一个名为uploads
的文件夹,确保此文件夹是可由适当的用户写入,对于我的系统,它是www-data
。我在linux上使用apache2,所以我的webroot是var/www
。
所以你应该在主文件夹中看到:
完成后,您将转到:
localhost/index.php/upload/
或index.php/upload/
的正确路径并再次测试。