【问题标题】:codeigniter cant upload imagecodeigniter无法上传图片
【发布时间】:2014-05-02 12:55:11
【问题描述】:

我在使用 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);
    }
}
  }
     ?>

当我上传一些图片时,请给我

    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

问题出在哪里?谢谢

【问题讨论】:

    标签: image codeigniter continuous-integration


    【解决方案1】:

    编辑:

    从您发布的链接中,我按照上传文件的指南进行操作,效果非常好。

    确保您已正确设置 CI:

    文件夹applicationsystem 以及文件index.php 必须上传到您的工作网络服务器,然后您必须创建一个名为uploads 的文件夹,确保该文件夹可由正确的用户写入,因为我系统是www-data。我在 linux 上使用 apache2,所以我的 webroot 是 var/www

    所以你应该在主文件夹中看到:

    • 应用
    • 系统
    • 上传
    • index.php

    完成后你会去:

    localhost/index.php/upload/index.php/upload/ 的正确路径并再次测试。

    【讨论】:

    • 同样的问题人...我尝试 3-4 个上传表单但不起作用..总是给我这个问题...
    • 好的,给我几分钟,我会和你一起解决这个问题。
    • 好的,谢谢。我不知道为什么这个表格不起作用......一切看起来都很好
    • 我唯一注意到的是 do_upload() 函数中缺少的 post 字段,再次查看所有内容。
    • 将名为function do_upload() 的函数更改为addfile() 并将表单调用更改为action="&lt;?=site_url('upload/addfile');?&gt;" 问题是您调用了一个内置函数并且您的函数名称与之匹配。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-31
    • 1970-01-01
    • 2020-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多