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

Link to comment
Share on other sites

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';

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.