skeay 发表于 2011-2-28 15:58:00

CI 上传的一个问题

本帖最后由 skeay 于 2011-2-28 16:03 编辑

管理员你好:
我在练习CI上传的时候:
member.php 是一个控制器,www是CI index.php和system所在目录


代码如下,先谢谢大大们。
member.php

function photo()
    {
      $config['title'] ="Post Photo";
      $config['url'] = base_url();
      $this->load->helper(array('form', 'url'));
      
      $this->load->view('header',$config);
      $this->load->view('action/photo',array('error' => ' ' )); //Change
      $this->load->view('admin_left');
      $this->load->view('includes/footer',$config);
    }

function photo_up()
    {
      $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->photo_up()) //这行出错了,和手册上一样的结构写就没有错误
      //手册上是有个控制器叫Upload,而我的控制器叫Member,把$this->upload->photo_up() 的upload改member也不对;也不知道这个upload是不是系统自带的,如果是的话不应该出错啊
      //用$this->photo_up();也不行会提示

//而加上了还是显示
//Fatal error:Call to undefined method CI_Upload::photo_up() in /opt/lampp/htdocs/www/application   /controllers/member.php
      {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('action/photo', $error);
      }
      else
      {
            $data = array('upload_data' => $this->upload->data());
            $this->load->view('upload_success', $data);
      }
    }

jeongee 发表于 2011-2-28 16:11:40

你那句要跟手册上写一样一样的 if ( ! $this->upload->do_upload()) ,不晓得你是怎么理解的呢?呵呵,深入理解手册,不要只看表面呢

skeay 发表于 2011-2-28 16:25:35

你那句要跟手册上写一样一样的 if ( ! $this->upload->do_upload()) ,不晓得你是怎么理解的呢?呵呵,深入 ...
jeongee 发表于 2011-2-28 16:11 http://codeigniter.org.cn/forums/images/common/back.gif

十分谢谢大大,呵呵解决了,我理解出错
手册上调用的方法名字和声明的是一样的名字
而在类中调用内部方法也是$this->方法名;
<?php
class Upload extends Controller
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())

skeay 发表于 2011-2-28 16:29:45

以前学ASP都是基于过程的
面向对象还不是熟,看来还得多练习
这样就明白了
<?php
class Uploadfile extends Controller
function to_upload()
{

CI贴11512 发表于 2011-7-1 11:29:51

我的也报错,是不是配置问题啊?怎么解决???{:soso_e183:}
页: [1]
查看完整版本: CI 上传的一个问题