[eluser]Dan Tdr[/eluser]
Hey..
i kind of have a problem.. i need some help in saveing the path of an uploaded image to a database.. and then display it from the database..
here is what i have for uploading the image:
controller:
Code:
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());
$this->load->view('upload_success', $data);
}
}
Upload
Code:
<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>
message after file upload :
Code:
<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>
</body>
</html>
after i upload a file the upload_success pops up and it gives me some info:
Code:
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<h3>Your file was successfully uploaded!</h3>
<ul>
<li>file_name: wc4.jpg</li>
<li>file_type: image/jpeg</li>
<li>file_path: E:/xphpx/xampp/htdocs/clasa/uploads/</li>
<li>full_path: E:/xphpx/xampp/htdocs/clasa/uploads/wc4.jpg</li>
<li>raw_name: wc4</li>
<li>orig_name: wc.jpg</li>
<li>file_ext: .jpg</li>
<li>file_size: 13.55</li>
<li>is_image: 1</li>
<li>image_width: 320</li>
<li>image_height: 301</li>
<li>image_type: jpeg</li>
<li>image_size_str: width="320" height="301"</li>
</ul>
<p><a href="http://localhost/clasa/index.php/upload.html">Upload Another File!</a></p>
</body>
</html>
in this message it displays some things that i could use to put the path into the database.. i could only put the file name and extension into the database and then call if from the database
i could do that with something like :
Code:
<?php
$upload_folder='uploads/'
foreach ($user_profile as $field=>$profile)
{?>
<img src="<?=base_url().$upload_folder.$profile?>" />
<?php }?>
could some one help me please? i`m sure it`s not that hard.. just that i don`t have the experience needed to see how to do it
if someone could help i would be realy grateful
thanks,
Dan