记录每月用户上传到我们的网络应用程序的最佳方式是什么?

发布于 2024-08-30 20:27:42 字数 718 浏览 2 评论 0原文

我们的 Web 应用程序允许用户上传照片,它使用在 Amazon EC2 上运行的 LAMP 服务器上的 PHP 脚本来处理图像上传,使用 Amazon S3 来存储文件,并使用 MySQL 数据库来记录有关图像的数据(用户 ID、文件名、标签) ETC)。

我打算在数据库中有一个 image_uploads 表,其中每个月有一列,每个用户一行。这样我就可以跟踪上传趋势。也可能有视频上传,所以我也会有一个 video_uploads 表。此外,用户可能属于多个组,并且我想跟踪每个组的每月上传量,因此可能还有一个 group_uploads 表。这意味着对于上传的每个文件,都会有 2 个 sql 更新查询 - 更新 image_uploads 和更新 group_uploads。

  1. $filesize = $_FILES['文件数据']['大小'];
  2. UPDATE image_uploads SET data_in_bytes = (data_in_bytes + $filesize) WHERE Month = $current_month ...(例如 - 我知道这不是正确的sql)

或者可能有一个长表来记录有关每次上传的数据(日期、用户、大小) , 媒体)。这样我就可以随时在数据库中查询我想要的信息 - 例如每个用户每月上传的数据 = data_in_bytes 的总和,其中 user = ## 和month = currentMonth

此类任务的最佳实践是什么?

问候

Our web application allows users to upload photos, it uses a PHP script on a LAMP server running on Amazon EC2 to handle image uploads, Amazon S3 to store the files and a MySQL database for recording data about the image (user id, filename, tags etc).

I intend to have an image_uploads table in the database with a colum for each month and a row for each user. That way I can track trends in uploads. There may be video uploaded too, so I would also have a video_uploads table. Additionally users may belong to a number of groups and I want to track monthly uploads per group, so would probably have a group_uploads table also. This means that for each file uploaded there would be 2 sql update queries - update image_uploads and update group_uploads.

  1. $filesize = $_FILES['Filedata']['size'];
  2. UPDATE image_uploads SET data_in_bytes = (data_in_bytes + $filesize) WHERE month = $current_month ... (for example - i know this is not correct sql)

Alternatively there could be a long table that records data about each upload (date, user, size, media). That way I can always query the database for the info i want - eg monthly uploads per user = sum of data_in_bytes WHERE user = ## and month = currentMonth

What are the best practices for this kind of task?

regards

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一身仙ぐ女味 2024-09-06 20:27:42

我将保留一个包含所有上传的主日志表,然后在该表中查询您想要的日期:

SELECT *
FROM logs
WHERE upload_date between to_date ('2003/01/01', 'yyyy/mm/dd')
AND to_date ('2003/12/31', 'yyyy/mm/dd');

I would keep a master log table with all of the uploades and then query the table for the dates that you want:

SELECT *
FROM logs
WHERE upload_date between to_date ('2003/01/01', 'yyyy/mm/dd')
AND to_date ('2003/12/31', 'yyyy/mm/dd');
血之狂魔 2024-09-06 20:27:42

请问为什么需要单独的group_uploads表?

为什么不拥有一个具有如下模式的表:uploads(user_id, group_id, filename, type, size, date)。如果允许用户为自己上传文件(不与组关联),则“group_id”可以为 NULL,并且“type”可以是“视频”或“图像”。如果您想添加其他文件类型(文档、mp3 等),这种方法似乎更灵活一些。

使用此架构,对各种过滤器的查询(按用户过滤、用户非组过滤、用户和组过滤、按类型过滤、按日期过滤)应该更简单。

希望有帮助。

May I ask why you need a separate group_uploads table?

Why not have a table with a schema like this: uploads(user_id, group_id, filename, type, size, date). Where "group_id" could be NULL if the user is allowed to upload files for himself (not associated to a group) and "type" would be either "video" or "image". This approach seems to be a bit more flexible in case if you want to add other file types (documents, mp3, etc).

With this schema, queries for various filters (filter by user, user and not group, user and group, by type, by date) should be simpler.

Hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文