PDA

View Full Version : Export all files from Blob to file system


dprichard
02-19-2010, 07:49 PM
A client moved over their database to our server and it has a table with a BLOB column and we are trying to export it to files. There is a mix of file types and I was wondering if anyone knew where I could find a tutorial on exporting the blob data into the file system. I have done few google searches, but am coming up with how to do jpg only. I have a column in the table with the file names and document file types.

SKDevelopment
02-20-2010, 08:50 AM
You would need a language like PHP for it.

I would run SELECT DISTINCT on the file type column to get the list of file all types contained in the table and which need to be dealt with.

Then I would check if there are no duplicate file names with something like

SELECT filename
, COUNT(filename) AS cnt
FROM mytable
GROUP
BY filename
HAVING cnt>1

I would think what to do with duplicate file names if any are returned.

Then I would create a simple PHP script which would run through all rows one by one and save them with fopen() (http://php.net/fopen)/fwrite() (http://php.net/fwrite)/fclose() (http://php.net/fclose) or file_put_contents() (http://php.net/file_put_contents).