Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 1.10 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ## Controller
  2.  
  3. <?php
  4.  
  5. class Welcome extends Controller {
  6.  
  7.         function Welcome()
  8.         {
  9.                 parent::Controller();  
  10.                 $this->load->helper('form');
  11.         }
  12.        
  13.         function index()
  14.         {
  15.                 $this->load->view('welcome_message', array('error' => ''));
  16.         }
  17.         function do_upload()
  18.         {
  19.                         $config['upload_path'] = './uploads/';
  20.                         $config['allowed_types'] = 'gif|jpg|jpeg|png';
  21.                         $config['max_size']     = '100';
  22.  
  23.                         $this->load->library('upload', $config);
  24.  
  25.                         if ( ! $this->upload->do_upload())
  26.                         {
  27.                                 $error = array('error' => $this->upload->display_errors());
  28.  
  29.                                 $this->load->view('welcome_message', $error);
  30.                         }
  31.                         else
  32.                         {
  33.                                 $data = array('upload_data' => $this->upload->data());
  34.                                 var_dump($data);
  35.                                 die();
  36.                         }
  37.  
  38.         }
  39. }
  40.  
  41. /* End of file welcome.php */
  42. /* Location: ./application/controllers/welcome.php */
  43.  
  44. ## View
  45.  
  46. <html>
  47. <head>
  48. <title>Upload Form</title>
  49. </head>
  50. <body>
  51.  
  52. <?php echo $error;?>
  53.  
  54. <?php echo form_open_multipart('welcome/do_upload');?>
  55.  
  56. <input type="file" name="userfile" size="20" />
  57.  
  58. <br /><br />
  59.  
  60. <input type="submit" value="upload" />
  61.  
  62. </form>
  63.  
  64. </body>
  65. </html>