Welcome Guest, Not a member yet? Register   Sign In
How to get file name to be inserted to database ?
#1

[eluser]dimasVS[/eluser]
Hi all,,
I want to know, how to get the name of file that had been encrypted ???
I'll use that name to be inserted into database.

this is my script :

function do_upload(){
$n = rand(0,100000);
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['encrypt_name'] = "$n";
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());

$this->load->view('admin/employeeAdd', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
echo "Register Successfull<br />";
echo anchor(base_url().'index.php/admin/employee', 'Back');
}
}

how to get the value of $config['encrypt_name'] or $config['file_name'] ?

and how to throw it to models ?

thanks so much
#2

[eluser]Derek Allard[/eluser]
Look for $this->upload->data() on file uploading doc page.
#3

[eluser]dimasVS[/eluser]
sorry but,,
how to get the value of that array ??

I tried to use
echo $this->upload->data('file_name');
but didn't give me the name of file.

thanks Derek,
#4

[eluser]ciGR[/eluser]
Hi,
try this
Code:
$img_data = $this->upload->data();
$file_name = $img_data['file_name'];

Also I see in your code the
Code:
echo anchor(base_url().‘index.php/admin/employee’, ‘Back’);
It's not required the base_url and the index page,
you can write
Code:
echo anchor('admin/employee','Back');

Hope to help you.
#5

[eluser]dimasVS[/eluser]
wow...
thank you so much cigr...
now, I got that value...
Big Grin

but now, how to send $file_name value to models ???
#6

[eluser]Derek Allard[/eluser]
Take a read through the userguide again dimasVS, I think it'll be helpful.

After you've read it, if things still aren't clear, could you show me the code you'd use to pass $name into the "new_person()" function of the following model? Notice that I'm taking File Uploading completely out of the equation.

Code:
$this->load->model('people_model');

$name = "Derek";
$this->people_model->new_person();
#7

[eluser]ciGR[/eluser]
Have you create the model?
In model you must have create the appropriate functions.

For example,

Code:
class Model_name extends Model {

    function __construct()
    {
        parent::Model();
    }

    function save_image($image_name = '')
    {

        $this->db->insert('your_table_name',Array('image'=>$image_name));
    }
}

and in your controller after successful image upload you must load the model and call the function with the image name like the argument
Code:
$this->load->model('Model_name');
$this->Model_name->save_image($file_name);
#8

[eluser]Derek Allard[/eluser]
Right, exactly. So back to your question
Quote:how to send $file_name value to models ???
The exact same way.
Code:
$this->load->model('Model_name');

$img_data = $this->upload->data();
$file_name = $img_data['file_name'];

$this->Model_name->save_image($file_name);
#9

[eluser]dimasVS[/eluser]
[quote author="ciGR" date="1266262210"]Have you create the model?
In model you must have create the appropriate functions.

For example,

Code:
class Model_name extends Model {

    function __construct()
    {
        parent::Model();
    }

    function save_image($image_name = '')
    {

        $this->db->insert('your_table_name',Array('image'=>$image_name));
    }
}

and in your controller after successful image upload you must load the model and call the function with the image name like the argument
Code:
$this->load->model('Model_name');
$this->Model_name->save_image($file_name);
[/quote]

Ok,, :-)
I got the value and successfully inserted to database...
#10

[eluser]dimasVS[/eluser]
[quote author="Derek Allard" date="1266262377"]Right, exactly. So back to your question
Quote:how to send $file_name value to models ???
The exact same way.
Code:
$this->load->model('Model_name');

$img_data = $this->upload->data();
$file_name = $img_data['file_name'];

$this->Model_name->save_image($file_name);
[/quote]

Thanks Derek,,
it really help me...
Now I could get the $file_name value and successfully inserted..

hmm,, once more.. :-)
how if it's not only $file_name...

for example I wanna throw the values of $file_name, $file_type, $username ???
and how to get the value of each variable in models...

Now, I usually create session first...




Theme © iAndrew 2016 - Forum software by © MyBB