Converting files to blob to save in database

Posted by jimbo on Stack Overflow See other posts from Stack Overflow or by jimbo
Published on 2012-09-06T09:29:19Z Indexed on 2012/09/06 9:38 UTC
Read the original article Hit count: 154

Filed under:
|
|

I have an old user site that we are currently updating. The site's users have previously uploaded profile pics that are stored in a directory. I am now wanting to keep these profile images in the database, (easy to backup all data) but am having trouble working out how to do it.

There are a lot of tutorials talking about do ing this from files that have just been uploaded and using the tmp name etc, but how can I re-create with files that have already been uploaded?

I have looked into $data = file_get_contents($filename); Which seems to create a binary file, but doesn't seem to save in database with:

mysql_query("UPDATE profiles SET company_logo = mysql_real_escape_string('".$data."') WHERE id = 1 ") or die(mysql_error());

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql