• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
save image path to database and then display it

#1
[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 />

&lt;input type="submit" value="upload" /&gt;

&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;
message after file upload :
Code:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Upload Form&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

<h3>Your file was successfully uploaded!</h3>

<ul>
&lt;?php foreach($upload_data as $item => $value):?&gt;
<li>&lt;?php echo $item;?&gt;: &lt;?php echo $value;?&gt;</li>
&lt;?php endforeach; ?&gt;
</ul>

<p>&lt;?php echo anchor('upload', 'Upload Another File!'); ?&gt;</p>

&lt;/body&gt;
&lt;/html&gt;

after i upload a file the upload_success pops up and it gives me some info:
Code:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Upload Form&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

<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>

&lt;/body&gt;
&lt;/html&gt;

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:
&lt;?php
$upload_folder='uploads/'
        foreach ($user_profile as $field=>$profile)
        {?&gt;
<img src="&lt;?=base_url().$upload_folder.$profile?&gt;" />  
&lt;?php }?&gt;

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

#2
[eluser]mdowns[/eluser]
Could you be a little more specific as to what the problem is?

#3
[eluser]Dan Tdr[/eluser]
i don`t know how i could store the image name and extension into a database after i uploaded it on my server so that i could output it on a user profile

#4
[eluser]mdowns[/eluser]
First get the full path of the image you uploaded. Read more about the File Uploading Class in the user guide.
Code:
$filepath = $this->upload->data()['full_path'];

Then insert that into your database.

Hope that helps.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.