You are here: Re: how do I store a binary file in a MySql database, as a string? « PHP Programming Language « IT news, forums, messages
Re: how do I store a binary file in a MySql database, as a string?

Posted by Henrik Hansen on 05/18/06 14:55

Alan Little <alan@n-o-s-p-a-m-phorm.com> writes:

> Carved in mystic runes upon the very living rock, the last words of
> Henrik Hansen of comp.lang.php make plain:
>
>> "lawrence k" <lkrubner@geocities.com> writes:
>>
>>> Is it right to say that I can just open any file with file(), get it
>>> as a string, and then store in a MySql database, in, say, a
>>> MediumText field? I realize that MySql supports binary fields, but my
>>> current MySql schema does not have any binary fields, and I'm
>>> wondering if I can store the file without changing my current schema.
>>
>> AFAIK you need to use blob fields as your data is binary (or is it,
>> what kind of files do you want to open?), if you store
>> it in a normal text field it can be corrupted. But else you are right,
>> you just take the ourput from the field and put in a file or output to
>> the browser with a header infront.
>
> You could base64_encode() it first.

But then you have to keep in mind the content will take up much more
space.

Just tested, a 91959 bytes files will become 122612 bytes, that will end up
being alot if you have lots of files..

But it's a working solution if you cant convert to a BLOB (can't see
why not though).

--
Henrik Hansen

 

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

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