christh Posted April 24, 2012 Share Posted April 24, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/261530-rebuildconvert-orginal-document-from-blob/ Share on other sites More sharing options...
silkfire Posted April 24, 2012 Share Posted April 24, 2012 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'; Quote Link to comment https://forums.phpfreaks.com/topic/261530-rebuildconvert-orginal-document-from-blob/#findComment-1340096 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.