开发者

Images in MySQL

开发者 https://www.devze.com 2022-12-10 14:06 出处:网络
Is there a Image related data type in MySQL that c开发者_如何学Pythonan be used for storing images for each recor?Performance-wise it\'s probably better to store the file as a file on the drive and on

Is there a Image related data type in MySQL that c开发者_如何学Pythonan be used for storing images for each recor?


Performance-wise it's probably better to store the file as a file on the drive and only write the filename or filepath and maybe the mime type into the database. But as the others say, BLOB is what you seek.


Like said before, blob is the way to go, however, as SanHolo points out it's not really performance-wise and you will eventually run into problems as your database can grow really really fast!

Why don't you index the file-name on the database and store the file on the server?

The mainly reason to not allow something like this would be security issues. If you are really trying to cover your bases by not allowing all users to see or grab content you have two options.

Option A) give the file a unique, non-identifiable name like Flickr does. The name of the file comprehends two hashes. A user hash and a file-hash. The second hash is secret and the only way you could get it would be by trial and error. Take a look into this file I have on Flickr. Is user-protected (only family can see) but you will be able to access it just fine as the URL itself serves as a protection: http://farm2.static.flickr.com/1399/862145282_bf83f25865_b.jpg, even if you were randomly trying to generate hashes and found a valid one it would be hidden by anonymity as you wouldn't know who it was from.

Option B) use a server side thecnology to limit the access. This method is safer but more expensive to the server. You will set up a script that will allow/deny access to the file based on session_permissions or something alike. Look at the following code that would be called by accessing something like:

http://yourserver.com/getprotectedfile.php?filename=213333.jpeg

session_start();

// logic to verify the user is ok
if($_SESSION['user_access']!=true) {
    exit('user not allowed here');

// WATCHOUT! THIS IS NOT SECURE! EXAMPLE ONLY.
// on a production site you have to be sure that $filename will not point to a system file
$filename = $_GET['filename'];

// gets the file and outputs it to the user
header('Content-type: image/jpeg');
header('Content-Length: '.filesize($filename));
readfile($filename);


You'll need to use some sort of BLOB type:

MySQL Reference: BLOB and TEXT types

Which type you use depends on the size of the image you wish to store.


Try one of the BLOB data types.


Yes , there are some datatypes to store image into database.

BLOB (Binary large object) which can be specially use for Storing of image files into database.

The four BLOB types are ' TINYBLOB ',' BLOB ', ' MEDIUMBLOB and 'LONGBLOB '. These differ only in the maximum length of the values they can hold.

Creating table:

CREATE TABLE image (imgname VARCHAR(33) , photo LONGBLOB );

For inserting Values refer to Insert Picture into SQL Server 2005 Image Field using only SQL

I have Stored one image file in database by using java jdbc, So if you want to see how image file is stored in database click the link : https://ibb.co/frCpt37

0

精彩评论

暂无评论...
验证码 换一张
取 消