PHP 是否在 MySQL 中存储图像? [英] PHP to store images in MySQL or not?

查看:19
本文介绍了PHP 是否在 MySQL 中存储图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 PHP 构建了一个小型 Web 应用程序,用户必须首先登录.当他们登录后,我打算在他们的个人资料"中显示一个小缩略图.

I have built a small web application in PHP where users must first log in. Once they have logged in, I intend on showing a small thumbnail as part of their "profile".

我必须确保图像小于特定尺寸以节省空间,或确保其具有特定分辨率,或两者兼而有之,或者甚至可能使用诸如 image magick 之类的东西将其缩小.
不确定最好的方法是什么,欢迎提出任何想法.

I will have to ensure the image is below a particular size to conserve space, or ensure it is a particular resolution, or both, or even perhaps use something like image magick to scale it down.
Not sure what the best approach for that is yet, any ideas welcome.

此外,我一直在尝试将图像作为 blob 存储在 MySQL 的 users 表中,或者单独的 images 表中是否更好使用唯一的 id,并将适当的图像 id 存储在 users 表中,或者简单地将上传的文件保存在服务器上(也通过上传页面)并将文件保存为 theUsersUniqueUsername.jpg.最佳选择?

Also, I have been trying to work out if it is better to store the image in the users table of MySQL as a blob, or maybe a separate images table with a unique id, and just store the appropriate image id in the users table, or simply save the uploaded file on the server (via an upload page as well) and save the file as theUsersUniqueUsername.jpg. Best option?

我在这里找到了有关将图像保存到 mysql 的教程:http://www.phpriot.com/articles/images-in-mysql

I found a tutorial on saving images to mysql here: http://www.phpriot.com/articles/images-in-mysql

我只是一个业余程序员,以前从未做过这样的事情,因此非常感谢示例和/或大量细节.

I am only a hobby programmer, and haven't ever done anything like this before, so examples, and/or a lot of detail is greatly appreciated.

推荐答案

总是取决于上下文,但通常,我将用户图像存储在文件系统中名为 /content/user/{user_id}.jpg 的文件夹中 并尽量少打扰数据库.

Always depends of context, but usually, I store a user image on the filesystem in a folder called /content/user/{user_id}.jpg and try to bother the database as little as possible.

这篇关于PHP 是否在 MySQL 中存储图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆