我该如何存储这张图片?

时间:2014-02-07 00:02:09

标签: file size

我目前有一堆小图片,我将其保存到文件夹中的服务器上。

  

将base64字符串存储到中是否更方便?   数据库,什么时候需要拔出来?

我最终寻找一种节省磁盘空间的方法,我正在寻找的方法需要能够承受繁重的流量。最少4M用户。

所有4M用户都会看到图片。

经常检索这样的数据会不会很糟糕?

如果我正在使用数据库,我将使用mysqli和PHPmyadmin。

实验: 用图像测试:Cute.jpeg 尺寸:2.65kb 磁盘大小:4.00kb

Base64字符串:

/9j/4AAQSkZJRgABAQAAAQABAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2NjIpLCBxdWFsaXR5ID0gNzUK/9sAQwAIBgYHBgUIBwcHCQkICgwUDQwLCwwZEhMPFB0aHx4dGhwcICQuJyAiLCMcHCg3KSwwMTQ0NB8nOT04MjwuMzQy/9sAQwEJCQkMCwwYDQ0YMiEcITIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIy/8AAEQgAZABkAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoK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1ZJs2jNbEk8qr2HPQVnxay9nO25iY3PQdj7f41nXl+fKaTcdozk+lZk0jSKSW5bgY9Kx5ralyaOnutWjniLxNkDPANebeJmW+lOUYOp+9jk1tC/+zK7KMgdQe4qJ44NRh8w/KwJ4PvWlPEWXvGT1OFSxleVY8cE4zXaaDI2lA2+0BVOGbqSaprpMYm3qudhB+8auXCmNpT6sP581f1m8rIizvY6+XXYV09kkl4wffHv+FYw1CW9ujPM7FyAB7D0965+WZjKtsh5PJI7GtW0VYUXPAUcZ71lOo73HbW50NgztOTHnYgAI9z/AIf1rsNMlIAzXDadIokgXdkmRmbH0/xrrLPzXbKtxW9GaJZ1i3DKoCjIxRVSCUCIDIyOtFd3OYM5SyuZTYXJ3HIuCM/XmuWtp5G1KS2Y5jZS3uCASOaKK8OX2fQuXwonKK8ZVgCGyD+ZFVYVBvojyNkoVQOw6UUVz1G7ItvY5q4P+n3Ef8IxgfjViMlYEwcZkFFFdP2V8gRo2iKyMxHJ5P50l8AdNuhjoSQe/Siio/5eL+uxfUy7BAbKOT+PzCM9+9bskjShS/JYZP1oorKu9fmzN/CXLS2j+0IBkYUng49K3tJZ/socuxJBJyaKK66Px/15DluWLad5TMzHkyf0FFFFaJuxys//2Q==

Base64字符串长度:3628

测试: Varchar(3628)是3629字节,保留1字节的字节长度。

所以字符串的总大小是~3.5kb

结论:我节省了大约0.5kb

我可能没有考虑过Mysqli表的字节大小。如果表字节大小保留为0.5kb或更多那么这将是不合理的,我应该在本地存储我的图像。

1 个答案:

答案 0 :(得分:-1)

首先,如果您将二进制数据存储在数据库中,您应该真正查看BLOB数据类型系列(LONGBLOB,TINYBLOB等)。忘记节省0.5kb的存储空间;使用正确的类型并尽量减少您必须进行的其他转换。只是我的两分钱。

如果您担心流量过大,我认为将文件本身存储在数据库中是不可能的。您可以自己运行一些基准测试来确定所涉及的开销量,但从我所看到的情况来看,在这些情况下将文件存储在磁盘上并将路径仅存储在数据库中(以及元数据或其他任何其他内容)通常非常标准需要)。这样您就不会使数据库负担过重(如果需要扩展,我发现扩展文件系统和/或Web服务器比增加数据库容量更容易)。