[thelist] Extracting (compressed?) files from a MySQL database

Roel Mulder roel.mulder at gmail.com
Fri May 6 04:47:22 CDT 2016


Hi all,
The following challenge is facing me. A client requested me to help get his
files out of a MySQL database. The developer of their system is gone,
history being what it is.

I'm facing 26268 records with a total 1.8GB filesize in MySQL.
What i did in PHP: query the file_content (MEDIUMBLOB), file_name,
file_date, LIMIT 10.

while ($row = mysql_fetch_array($result)) {
  $file = fopen('/var/www/vhosts/path/'.$row['file_name'], 'w+');
  fwrite($file, $row['file_content']);
  fclose($file);
  touch('/var/www/vhosts/path/'.$row['file_name'],
strtotime($row['file_date']));
}

This gives me the files (.doc .docx .pdf .msg), however I can't open them
with their default programs. Opening them in a text editor does show code
and fragments of text.
Could the files be compressed prior to storing in MySQL?
  fwrite($file, gzdeflate($row['file_content']));

Now I can open them with their default program, to see many paged documents
with unreadable text fragments.

Does anyone have suggestions on how to extract them files to usable
conditions?
Cheers, Roel


More information about the thelist mailing list