Welcome Guest, Not a member yet? Register   Sign In
Saving files to a database
#1

[eluser]bikuta[/eluser]
Hi guys,

I've been looking at the File uploading class in CI and it seems that it uploads the file to a folder on the server. What I'm looking for is a way to upload the file to the database instead of the file system.
Is there an example of how to go about doing this?
#2

[eluser]Lockzi[/eluser]
My guess is...

First start off with reading in the whole file, then save it into the database in a text-type field.

Just a generall idea. Smile
#3

[eluser]bikuta[/eluser]
ok..
how would I do this by using active record?
#4

[eluser]Lockzi[/eluser]
Active record is just another way to insert data into the database.

Active Record Insert
$data = array(
'title' => $title,
'name' => $name,
'date' => $date
);

$this->db->insert('mytable', $data);

// Produces: INSERT INTO mytable (title, name, date) VALUES ('{$title}', '{$name}', '{$date}')

I guess those other file upload codes you have would include the bufferings.
What I would try then is something like this

$fileUploadBufferFromOriginalCode = (whatever the variable is);

$databaseInput .= $fileUploadBufferFromOriginalCode;

And then later when the whole file has been buffered I would do something like this

$fileData = array(
fileName => $theVariableThatContainsFileName,
fileData => $databaseInput
);




Theme © iAndrew 2016 - Forum software by © MyBB