shiva478 Posted August 22, 2012 Share Posted August 22, 2012 Hi I'm new to php and codeigniter. I was doing a tutorial on file uploading class in http://codeigniter.com/user_guide/libraries/file_uploading.html I was able to insert the image path into my database. The only problem I have is that I want to view the images on the upload_success view and I'm not sure how I go about doing that. The only thing I can get is a list of information about the image. This is my upload controller <?php class Upload extends CI_Controller { function __construct() { parent::__construct(); $this->load->model('upload_model'); $this->load->helper(array('form', 'url')); } function index() { $this->load->view('upload_form', array('error' => ' ' )); } function do_upload() { $config['upload_path'] = './uploads/'; $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()) { $error = array('error' => $this->upload->display_errors()); $this->load->view('upload_form', $error); } else { $data = array('upload_data' => $this->upload->data()); $upload_info = $this->upload->data(); $insert_data = array( 'id' => $this->input->post('id'), 'image_path' => $upload_info['file_path'] ); $this->db->insert('image', $insert_data); $this->load->view('upload_success', $data); } } } ?> This is my upload_model <?php class Upload_model extends CI_Model { public function __construct() { $this->load->database(); } public function get_upload() { $query = $this->db->get('image'); } } ?> This is my upload_form view <html> <head> <title>Upload Form</title> </head> <body> <?php echo $error;?> <?php echo form_open_multipart('upload/do_upload');?> <input type="file" name="userfile" size="20" /> <br /><br /> <input type="submit" value="upload" /> </form> </body> </html> and this is my upload_success view <html> <head> <title>Upload Form</title> </head> <body> <h3>Your file was successfully uploaded!</h3> <ul> <?php foreach ($upload_data as $item => $value):?> <li><?php echo $item;?>: <?php echo $value;?></li> <?php endforeach; ?> </ul> <p><?php echo anchor('upload', 'Upload Another File!'); ?></p> <?php endforeach; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/267413-view-image/ Share on other sites More sharing options...
spiderwell Posted August 22, 2012 Share Posted August 22, 2012 you should try the codeigniter forums for this , they are pretty good and you will find more users who know this framework. Quote Link to comment https://forums.phpfreaks.com/topic/267413-view-image/#findComment-1371384 Share on other sites More sharing options...
shiva478 Posted August 22, 2012 Author Share Posted August 22, 2012 Thanks I will do that Quote Link to comment https://forums.phpfreaks.com/topic/267413-view-image/#findComment-1371388 Share on other sites More sharing options...
Mahngiel Posted August 23, 2012 Share Posted August 23, 2012 take a look at the Media library i have in my signature. it'll make uploading a snap for you. In regards to showing the last uploaded item: after you insert into the database, run $this->db->insert_id() to get the table ID number for the image. you can use that to retrieve the image from the DB whenever you want to call it. Quote Link to comment https://forums.phpfreaks.com/topic/267413-view-image/#findComment-1371795 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.