Welcome Guest, Not a member yet? Register   Sign In
Question about Uploading image
#1

[eluser]kikz4life[/eluser]
Hi to all,

I've been exploring more in CI framework community and i've bumped into this: http://ellislab.com/codeigniter/user-gui...ading.html. Its about uploading an image.

Here is my help question how can i save the image file_name in the db. Could anyone show me the light? huhu. Cant figure out how can i call the file_name and insert it to the table field. Do i need to create a model in this?

Code:
<?php
    class Upload_model extends Model {

    
        function Upload_model()
        {
            parent::Model();
        }
.......................
.....??

Thanks
-Dean
#2

[eluser]saidai jagan[/eluser]
U should rename the file, Because there ll be a mistake with same file names.. So u shd do like
17_thumb.jpg.where 17 is the user id who uploads the image.Thumb is the size
#3

[eluser]kikz4life[/eluser]
i'll post the controller & view for quick response to all.

controller
Code:
<?php
at_reports.php
class At_reports extends Controller {
    
    function At_reports()
    {
        parent::Controller();
        $this->load->helper(array('form', 'url'));
    }
    
    function index()
    {    
        $config['upload_path'] = './reports/module/';
        $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);
        }
    }

}
?>

View
upload_form.php
Code:
<html>
<head>
<title>Upload Form</title>
</head>
<body>

<?php echo $error;?>

<?php echo form_open_multipart('at_reports');?>

<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;
#4

[eluser]kikz4life[/eluser]
@saidai jagan

i dont have to change the filename of image coz if ive uploaded same image its filename automatically increment (ie. pic.png then save again pic1.png.., pic2.png so on..)

but how can i save the file_name to the database table field? could anyone show me a model for this? Sad(

thanks in advance
-Dean
#5

[eluser]flaky[/eluser]
Code:
if (!$this->upload->do_upload('upload_file')){
    echo $this->upload->display_errors();
}
else{
    $file_data = $this->upload->data();
    $file_name = $file_data['file_name']; //example: image.jpg
}
#6

[eluser]kikz4life[/eluser]
hi there flaky

thanks for the pointer, got it saved Smile

Thanks
-Dean




Theme © iAndrew 2016 - Forum software by © MyBB