You are here: Re: Mapping binary data into the filesystem « PHP Programming Language « IT news, forums, messages
Re: Mapping binary data into the filesystem

Posted by Jerry Stuckle on 11/07/06 21:05

Rudi Menter wrote:
> Jerry Stuckle write:
>
>
>>Rudi Menter wrote:
>>
>>>Hi, I would like to store binary data (as data-type blob) in
>>>a (MySql-) database, so I require functionality that allows
>>>a mapping from and back into the filesystem. Now, is there
>>>a library for this task that you know of?
>>>
>>>Thx,
>>>Regards
>>
>>No library I know of. It's not that hard to do. Just have a column in
>>your database which has the equivalent filename and search for the
>>appropriate one. i.e. if you were mapping "/members/memberpage.html",
>>just have a field with that string in it. Then you can easily search
>>for the string.
>>
>>Or am I missing something here?
>
>
> For instance, I'd like to
> 1) convert, say, a file 'explorer.exe' into a string, say, $blobbdata
> 2) store that in a blob of a database, which is straightforward
> 3) reread that, from the database into a string, say, $blobbdata
> 4) convert $blobbdata into a file, say 'explorer.exe', (and execute it)
>
> Sounds easy, no! ;)
>
> Regards

Not hard at all. Just read the file with fread() in binary mode.
INSERT it into your database with an appropriate key (i.e. 'explorer.exe');

When you want it, SELECT the blob from your database into a string. If
it's an executable, you'll need to write it to disk in binary mode, then
execute it with exec().

The main problem you will run into is the file size. The default memory
limit for PHP is 8M. You can change that in your php.ini file if
necessary. Alternatively, you can split the file into blocks and store
it in multiple rows with a sequence number.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация