Friday, September 9, 2011

File Upload CodeIgniter 2.0.2

create a folder myfile at the root (destination files). Create function (link) for upload form application/views/main.php: function upload() { $this->load->view('layout/head'); $this->load->view('upload'); $this->load->view('layout/foot'); } Create Upload Form application/views/upload.php: <?php echo form_open_multipart('index.php/main/uploadb'); echo " <input type='file' size='30' name='file'> <input type='submit' value='UPLOAD'> "; echo form_close(); ?> Create function for upload process application/controller/main.php: function uploadb() { $config['upload_path']='./myfile'; $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('file')) { $error=array('error' => $this->upload->display_errors()); redirect (base_url().'index.php/main/upload', $error); } else { $data=array('upload_data' => $this->upload->data()); redirect (base_url().'index.php/main/upload', 'refresh'); } }

0 komentar:

Post a Comment

Thanks a lot for your attention...

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Best Web Hosting