|
我做了个表单提交新闻还有上传图片 , 我这人比较笨
大概是 表单---》 验证表单---》 上传表单中的图片---》 获取图片的路径和文件名----》写入数据库
可是当我验证表单以后 如何跳转到 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(){
}
}
?>
谢谢 |
|