CodeIgniter Forums
Newbie: if using a model to update a database, how do i add upload data - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Newbie: if using a model to update a database, how do i add upload data (/showthread.php?tid=4756)



Newbie: if using a model to update a database, how do i add upload data - El Forum - 12-13-2007

[eluser]loopymonkey[/eluser]
I'm confused how this should be written using a model to add to my database:

Code:
function add_toMyDatabase()
  {
    $YourName = $this->input->post('YourName');
    $upload_data['file_name'] = $this->input->post('userfile');
    $this->db->query("INSERT INTO toMyDatabase (id, YourName, userfile) VALUES(NULL, '$YourName', '$userfile')");
  }

From a form i am uploading a person's name and the name of the file that i received. I know my $upload_data contains the information i need since i'm using the upload helper, I'm just not certain how i can get JUST the file_name and put it into my database's field called userfile.

Any leads or help appreciated!


Newbie: if using a model to update a database, how do i add upload data - El Forum - 12-13-2007

[eluser]loopymonkey[/eluser]
I think i just figured it out myself. I was just missing this in my model:

Code:
$upload_data = $this->upload->data();
$userfile =    $upload_data['file_name'];

just needed that upload_data line


Newbie: if using a model to update a database, how do i add upload data - El Forum - 12-14-2007

[eluser]blu3ness[/eluser]
side note: storing the file content directly into the database seems a bad idea to me :x. I'd rather let OS do the file handling and use the DB just to keep an index of it :O