Jump to content

view image


shiva478

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/267413-view-image/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/267413-view-image/#findComment-1371795
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.