Jump to content

Rebuild/Convert Orginal Document from BLOB


christh

Recommended Posts

Hi

 

I have a SQL database that stores uploaded documents broken into the format of FileName, FileType, FileSize, FileContent with the content being stored in a BLOB field.

 

When I need the file, it is downloaded by setting the headers accordingly and echoing the content which works great.

 

What I would like to do in certain instances is to rebuild the original file and save it into a temp folder on the server - is this possible and if so how would I achieve it?

 

I can see a number of articles on converting images back from BLOB using imagecreatefromstring() but nothing for .doc, .pdf etc.

 

Many thanks

 

Chris

Very simple. The BLOB field contains the raw data of the file and that is the only thing you require.

 

So if it's a doc document you could do something like:

 

file_put_contents('document.doc', $file_contents);

 

PHP makes reading and writing files a breeze!

 

Change the first argument if you need the file in another folder, e.g. '../../path/to/folder/document.doc';

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.