将文件信息存储在数据库中
我正在构建一个文件托管网站,并希望跟踪用户文件配额(每个用户仅允许 2GB 的文件存储)。谁能解释一下我如何在 mysql 数据库中存储用户上传的所有文件的文件名、类型和重要的大小。当用户超出限制时,是否可以使用 php 脚本或 MySQL 进行计算,显示一条消息并拒绝任何进一步的上传,直到他们删除文件以减少配额?
我对 mySQl 相当陌生,并且非常感谢一些关于如何实现这一目标的简单指南。
谢谢
R
I am building a file hosting site and would like to keep track of users file quota ( Each user is only allowed 2gb of file storage). Could anyone explain how I could store file name, type and importantly size of all files uploaded by a user in a mysql database. And is it possible to calculate using php script or MySQL when users exceed limit, display a message and reject any further uploads until files have been deleted by them to reduce quota?
I am fairly new to mySQl and would really appreciate some simple guides on how to achieve this.
Thanks
R
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简短回答
是的。
长答案
是的,但需要一些编码。
我建议:
您绝对可以在数据库中存储每个文件的文件名、文件类型和大小。
您可以使用此数据来确保用户还有剩余配额,并在用户达到配额后尝试上传文件时发出警告/阻止他们。
如果您是 MySQL / PHP 的新手,那么这听起来是一个很棒的项目,可以帮助您开始使用两者。
我推荐 Tizag 教程:PHP / MySQL。
学习完基础知识后,请阅读数据库规范化。
编辑:要使用 PHP 查找文件的大小,请使用 filesize。
Short Answer
Yes.
Long Answer
Yes but it will take some coding.
I recommend:
You definitely can store the file name, file type and size of each file in your database.
You can use this data to ensure that a user has quota remaining, and warn / block them when they try to upload files once they've reached their quota.
If you're new to MySQL / PHP, then this sounds like a great project to get you started with both.
I recommend the Tizag tutorials: PHP / MySQL.
Once you've covered the basics, please read about database normalization.
Edit: to find the size of a file with PHP, use filesize.