Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieve MS Word from longblob

Status
Not open for further replies.

Bersani

Programmer
Nov 10, 2011
48
US
I want to place a MS Word doc in longblob MySQL field. I want the Word doc to be in the table and not merely use the field as a placeholder for an external file location. Does anyone know the PHP code that I need? I have over 1000 records in this file and they are all MS Word doc.
 
the easiest way to do this is to store the escaped contents of the file (grabbed with file_get_contents) in the field.

Code:
$sql = "insert into mytable (id, filedata) values (NULL, '%s');
$query = sprintf($sql, mysql_real_escape_string(file_get_contents($absolutePathToMyFile)));
mysql_query($query) or die (mysql_error());
unset($query); //free memory

however you should be aware that there are very few pundits around who regard it as a good idea to store binary blobs (or files) in a mysql database. better to store them outside the webroot and build a document serving script.
 
I tried using a second field (text filed) to store the path of the file outside of the database. However, when I open the file (which is a MS Word .docx) it comes up in protected view, then I "enable editing" and make changes. However, whatever changes I make are NEVER saved and I always end up with the original file. I even tried svaing the file from the File save MS Word ribbon. That did not work. I have been using Foxpro with OLE2 embedded files in the database for 20 years with no problem. Now that Iw ant to migrate to MySQL - PHP, it seems that OLE2 embedding is not allowed and there is nothning to replace it.
 
I know of no way that you can retrieve a docx, work on it locally and have it automatically save back into a database. perhaps you could write a script to do this.

but instead perhaps services like skydrive, google drive, dropbox and others will at least achieve the synchronisation with the remote server and you can write some thing to serve you links to the file based on the relevant API.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top