用户
 找回密码
 入住 CI 中国社区
搜索
查看: 3607|回复: 3
收起左侧

对我这个菜鸟来说是个难题 请各位帮帮忙

[复制链接]
发表于 2008-6-25 10:45:55 | 显示全部楼层 |阅读模式
我做了个表单提交新闻还有上传图片   , 我这人比较笨   

大概是 表单---》 验证表单---》  上传表单中的图片---》 获取图片的路径和文件名----》写入数据库

可是当我验证表单以后  如何跳转到 do_upload()呢 ,我用了redirect(),但那个好像没有上传文件的信息

文件传不上去  ,去请教各位高人

<?
Class Advertisement extends Controller {
  
  function Advertisement(){
   
   parent::Controller();
   $this->load->database();
   $this->load->helper('form');
   $this->load->helper('url');
   $this->load->helper('array');
   $this->load->library('validation');
   
  }
  
  function index (){
   
   $this->load->view('form/form_add');
   
  }
  
  function form_valid(){
   
   $rules['title'] = "required";
   $rules['content'] = "required";
   $rules['upfile'] = "required";
//   $rules['email'] = "required";
   $this->validation->set_rules($rules);
   
   if ($this->validation->run() == FALSE){
     
     $this->load->view('form/form_add');
   
    }
    else{
     
     $this->do_upload();
//     redirect('/upload/do_upload');
     
    }   
   
  }
  
  function do_upload(){
   
     $config['upload_path'] = '/uploads/';
     $config['allowed_types'] = 'gif|jpg|png';
     $config['max_size'] = '100000';
     $config['max_width']  = '1024';
     $config['max_height']  = '768';
  
     $this->load->library('upload', $config);
   
     if ( ! $this->do_upload()){
      
       $error = array('error' => $this->upload->display_errors());
        $this->load->view('form/error', $error);
        
      }
      else
      {
}         
      $data = array('upload_data' => $this->upload->data());
       echo "success!!";
   
  }

  function data_insert(){
   
   
   
  }
  
}
?>

谢谢
 楼主| 发表于 2008-6-25 10:47:49 | 显示全部楼层
在线等  ......................
发表于 2008-6-25 11:01:24 | 显示全部楼层
呵呵 直接调用  do_upload 函数啊!
$this->do_upload()

if ( ! $this->do_upload()){
改成
if ( ! $this->upload->do_upload()){
 楼主| 发表于 2008-6-25 11:17:10 | 显示全部楼层
多谢 Hex的帮助啊   3QQQQQ

本版积分规则