I'm making use of codeIgniter to upload files into folders in the server. Now I also want to save the data into the database, what do I need in order to get the raw data and then save it into the database?
Here's the model for saving files:
<?php
class files extends ci_Model{
function saves($filename, $filedata, $post_id){
$this->db->query("INSERT INTO tbl_files SET file_data='$filedata', filename='$filename', postid='$post_id'");
}
}
?>
Here's how I call it from the upload controller:
$filename = $data['upload_data']['file_name'];
$file_data = file_get_contents($data['upload_data']['file_name']);
$this->load->model('files');
$this->files->saves($filename, $file_data, 'ID1');
Table Structure:
- file_data (LONG BLOB)
- filename (VARCHAR)