记录每月用户上传到我们的网络应用程序的最佳方式是什么?
我们的 Web 应用程序允许用户上传照片,它使用在 Amazon EC2 上运行的 LAMP 服务器上的 PHP 脚本来处理图像上传,使用 Amazon S3 来存储文件,并使用 MySQL 数据库来记录有关图像的数据(用户 ID、文件名、标签) ETC)。
我打算在数据库中有一个 image_uploads 表,其中每个月有一列,每个用户一行。这样我就可以跟踪上传趋势。也可能有视频上传,所以我也会有一个 video_uploads 表。此外,用户可能属于多个组,并且我想跟踪每个组的每月上传量,因此可能还有一个 group_uploads 表。这意味着对于上传的每个文件,都会有 2 个 sql 更新查询 - 更新 image_uploads 和更新 group_uploads。
- $filesize = $_FILES['文件数据']['大小'];
- 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.
- $filesize = $_FILES['Filedata']['size'];
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我将保留一个包含所有上传的主日志表,然后在该表中查询您想要的日期:
I would keep a master log table with all of the uploades and then query the table for the dates that you want:
请问为什么需要单独的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.