Image To Binary

I want to convert an uploaded image file to a binary file, so i can store the binary file to my database, so i can still retrive it later… I beleive it os possible with PHP but I dont knwo how… PLEASE HELP ME…

An image file is already a binary format.

It’s more common to just store the filename in the database, and leave the file in a directory. But, you can store the binary file contents if you really want.

Are there any complications that might come along with storing image files within a database?

I’ve wondered about using this method instead of leaving pictures in directories but don’t know what exactly what the implications would be of such a change.

There’s plenty of discussions(some even violent lol) about the pros and cons of storing images in a database. A search will yield a lot of results.

Storing image directly with blob in a database, or uploading to a directory. Which one is better??

In 99.9% cases you don’t want to store images in a DB.

Is there any reason why you’re even considering it?

I was thinking it could be possible for me to compress an image into bits before storing them to DB

I don’t know what you mean by saying “compress to bits”.

If the image is already in a compressed format (JPG, PNG, GIF, etc) then no compression will reduce its size.

I would go with the other way around, 99.9% of the time you would want images uploaded by users in the database.

It makes access, backup, insertion and so on much simpler and faster.

The only “problem” with images and database, is getting the image data in a variable,
Use ob start / end for that.

Once your image data is in a variable, you can do anything you want with it, zip it up some more, write it to a file, database (just make sure to escape the string), etc.

Thanks a lot, this very useful to me…

It makes access, backup, insertion and so on much simpler and faster.

I’s ridiculous. You can’t prove it.

Not ridiculous at all.

How good idea it is to store BLOBs in the database depends on the size of the files, the database system, and the file system. Generally a file belongs in the database when it’s below a certain threshold of file size, and it belongs outside the database when the file is larger than that.

Unfortunately, there is a severe lack of research in this area, and searching the Internet (and this forum) will only give you heated, unfounded arguments. I only know of a research paper considering NTFS and SQL Server.

The decision isn’t that important for most people’s sites, so it usually doesn’t matter which way they end up using. People are also using cloud hosting services nowadays, so it’s often a non-issue completely when it gets to the point that it matters.

There’s plenty of discussions

Don’t start another one.

But saying “database makes access, backup, insertion and so on much simpler and faster” is ridiculous.

And database is not an answer to the newbie, who have no clue.