Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // UNTESTED CODE !!!
- // Upload from a posted form with a file input called 'your_field_name'
- $config['upload_path'] = '/path/to/uploads/';
- $config['allowed_types'] = 'pdf|txt';
- $config['max_size'] = 1024; // 1 MB
- $this->load->library('upload', $config);
- this->upload->do_upload('your_field_name');
- if ($this->upload->do_upload()) {
- $uploaddata = $this->upload->data();
- }
- else {
- echo $this->upload->display_errors());
- exit;
- }
- // Insert into database, say for page #1
- $data = array('file' => $uploaddata['file_name], 'page_id' => 1);
- $this->db->insert('my_images_table', data);
- // In page, fetch the images with page #1
- $images = $this->db->where('page_id', 1)->get('my_images_table')->result_array();
- // Display download links for this page
- if ( count($images) ) {
- foreach ( $images as $image ) {
- echo anchor('url/to/uploads/' . $image, 'Download file ' . $image);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment