ifconfig1024 发表于 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(){
   
   
   
}

}
?>

谢谢

ifconfig1024 发表于 2008-6-25 10:47:49

在线等......................:Q :Q :Q :Q :Q

Hex 发表于 2008-6-25 11:01:24

呵呵 直接调用do_upload 函数啊!
$this->do_upload()

if ( ! $this->do_upload()){
改成
if ( ! $this->upload->do_upload()){

ifconfig1024 发表于 2008-6-25 11:17:10

多谢 Hex的帮助啊   3QQQQQ
页: [1]
查看完整版本: 对我这个菜鸟来说是个难题 请各位帮帮忙