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

查看:134
本文介绍了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".

我必须确保图像低于特定尺寸以节省空间,或确保它是特定分辨率,或两者兼有,甚至可能使用像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.

此外,我一直在尝试研究是否更好地存储图像MySQL的用户表作为blob,或者可能是具有唯一ID的单独的 images 表,并且只存储 users 表中的相应图片ID,或者只是将上传的文件保存在服务器上(也通过上传页面)并将文件另存为 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天全站免登陆