Guest User

balozi

a guest
Jun 19th, 2013
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.90 KB | None | 0 0
  1. <?php
  2.  
  3. // UNTESTED CODE !!!
  4.  
  5. // Upload from a posted form with a file input called 'your_field_name'
  6. $config['upload_path'] = '/path/to/uploads/';
  7. $config['allowed_types'] = 'pdf|txt';
  8. $config['max_size'] = 1024; // 1 MB
  9. $this->load->library('upload', $config);
  10. this->upload->do_upload('your_field_name');
  11.  
  12. if ($this->upload->do_upload()) {
  13.     $uploaddata = $this->upload->data();
  14. }
  15. else {
  16.     echo $this->upload->display_errors());
  17.     exit;
  18. }
  19.  
  20. // Insert into database, say for page #1
  21. $data = array('file' => $uploaddata['file_name], 'page_id' => 1);
  22. $this->db->insert('my_images_table', data);
  23.  
  24. // In page, fetch the images with page #1
  25. $images = $this->db->where('page_id', 1)->get('my_images_table')->result_array();
  26.  
  27. // Display download links for this page
  28. if ( count($images) ) {
  29.     foreach ( $images as $image ) {
  30.         echo anchor('url/to/uploads/' . $image, 'Download file ' . $image);
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment