How to store image [full_path] in database |
[eluser]Dchen05[/eluser]
I know this is a simple question and I have read the user guide on this subject. But I cannot figure out how to take the [full_path] from the array called upload_data and store it in a field called image_path in my database. All the text fields work fine in my form and get stored in the DB properly. What do I have to write in order to get just [full_path] into the database? Thanks guys! Here is the controller: Code: function do_upload() And the view: Code: <html>
[eluser]ciGR[/eluser]
Hi, You get the info that you want from the table data Code: $data = array('upload_data' => $this->upload->data()); For example you can get full_path The absolute server path including the file name or if you save the images in a concrete path, you can save only the filename in the database, that you can get after success upload from $data['file_name']
[eluser]Dchen05[/eluser]
Thanks for the response, My question is how do I get $data['file_name] into the DB. The other fields automatically went into the correct DB fields because they had the same name and were text I think. Can I set a variable something like this? $data["full_path"] = $filepath; $filepath->db->insert('characters', $_POST["filepath"]);
[eluser]ciGR[/eluser]
For example, you have a two fields in the database table title and image_path $filepath = $data['full_path'];(or you can save only the image name with $data['file_name']; $data = array( 'title' => 'The title for this image' , 'image_path' => $filepath ); $this->db->insert('your_table', $data); You save in the database the path(the path it's also text or better you can set it as varchar)
[eluser]Dchen05[/eluser]
Thanks so much for the help. Unfortunately I'm still getting an error. Do I have to declare $filepath as a variable before? A PHP Error was encountered Severity: Notice Message: Undefined index: full_path Filename: controllers/upload.php Line Number: 44 Code: function do_upload()
[eluser]cahva[/eluser]
You are assigning $this->upload->data() to $data['upload_data'] so thats why it couldnt find $data['full_path'] (so it would be found in $data['upload_data']['full_path'] ). Try: Code: $data = $this->upload->data();
[eluser]ciGR[/eluser]
Yes cahva has right, that's the way I use it, but in my first post I copy-paste from you post(and in user guide is with the same way) and post it.
[eluser]minagabriel[/eluser]
i usually do this at the controller : i save the file name string to a variable $x= $data['upload_file]['file_name']; and pass this variable to the model $this->load->model(any_model) $this->any_model->any_function($x) and ion the model : when inserting data $this->db->insert('any_table' , array('image_name'=>post_any , 'image_path'=>$x));
[eluser]adityajoshi[/eluser]
how do i get the file location of thumbs i mean resize image which i have in thumbs folder |
Welcome Guest, Not a member yet? Register Sign In |