I am working on PHP. My question is How can restrict a user can upload only three images in a month.
My Mysql Database table --
CREATE TABLE `images`
@fabrik solution is the simplest approach, but it has a cave-eat of performance decay when dealing with a lot of images/users.
If you dont mind to dig a bit more into the solution, I would suggest adding image_upload_credit
field to user table. Every time user uploads the image you would reduce the credit by 1.
Since you already have access to User
object at the time of upload (or should have), the complexity of insert is O(1)
.
To finish up the solution you need to write a cron
(periodically run) task which resets the image_upload_credit
on the first day of each month with UPDATE user SET image_upload_credit = 3 WHERE image_upload_credit <> 3;