holding image data on mysql

two things are needful fot holding image data on mysql

1/. A BLOB field so that the data is held truly 8 bit clean

2/. A way to inject it without trying to use tools designed for text.

I’ve used two methods. Both work.

(a) use the ‘load file’ command t tp transfer an image on disk to Msql.
It does however need special mysql privileges that are not always
available or safe..

2/. From PHP environment, I turn the image data into an enormous
hexadecimal number. MySQL seems able to understand that as niray data OK.

ie in PHP this is a valid way to include binary data in an UPDATE query

$query=sprintf(“update objects set thumbnail=0x%s, type=’%d’, uri=’%s’,
alt_text=’%s’, privilege_level=’%d’, filename=’%s’, size=’%d’,
content=0x%s, modified_by=’%d’, modified_on=now(), etag=md5(content)
where id=’%d'”, bin2hex($thumbnail), $mime,
$_POST[‘uri’],$_POST[‘descr’],$_POST[‘privilege_level’],$filename,
$size, bin2hex($code), $login_id,$id);

 

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.