![]() |
Attachment.php
Hello,
I was wondering about the following: If I download or view an attachment via the vBulletin attachment.php, would it be possible to write its filesize into the database? My idea is this: Every time a member downloads something, the filesize will be added to a user-specific table. Once the number in that table matches or is bigger than the allowed quota, the attachment.php would return an error. That quota-number in the table would then periodically be erased. Generally, the question is: Can I get this data (attachment filesize) and write it into the database? |
The filesize for each attachment is already stored in the database. It is stored in the "filesize" field in attachment.
|
Great, I have just installed a test installation and can see what you refer to.
I don't have the chance to check for filesystem attachments, but I assume it is the same method, each attachment getting its own attachment ID and the filesize info in the database. So in order to control a users bandwidth consumption, I would grab the attachments filesize when attachment.php is called and add it to the user specific attachment_quota table. Can you point me to a tutorial how to write vBulletin addons? As I tried looking around but didn't find anything. Or would you suggest that I hard-code it into the files? |
Gotta bump this. =)
|
There isn't really one particular tutorial on how to write a product. You can look through the articles forum, but I think most users learn by looking at other products to see how it was done.
|
Instead of patching the attachment system, you could try the Links and Downloads Manager, which includes bandwidth control. See url in my signature.
|
Quote:
Seeing how many attachments I am serving, I would prefer to have the limit as simple as possible. Only adding a new row to all members, summing and controlling their bandwidth usage that way. --------------- Added [DATE]1250388287[/DATE] at [TIME]1250388287[/TIME] --------------- Please bear with me. Since I have asked for an addon like this for several days and so far no one else sees its uses, I might want to try and code it myself with my rather limited knowledge of php and mysql. So if I want to start, I would like to ask you some questions. The hook to be used for an addon like this should be attachment_start, right? Then I want to write the code similar to this: Code:
GET attachment-filesize -> write filesize to member download quota table Is it a good approach? --------------- Added [DATE]1250393636[/DATE] at [TIME]1250393636[/TIME] --------------- So far, I got this: Code:
if($vbulletin-userinfo['usergroupid'] = 7) { $download_quota = 15728640; } // Moderators Then I set a different download quota for all existing usergroups. In this case it's 15 MB in bytes. Then I go check if the users current download_quota is less than the allowed 15MB. If that is the case, I will add the filesize of the current attachment to the download_quota field for the specific user. If it's bigger I return error. =) Is it that simple? |
Quote:
I'm not sure of the need for a separate table for the user group allowances, although this is a straightforward solution. Another approach would be to hold this array as a serialised string in the data cache. This would reduce the required sql traffic. |
Hi Andrew, thanks for your reply.
Since most of the attachments are pictures and less than 200KB in filesize, I wouldn't mind broken transfers. If in the membership plan 10MB bandwidth are mentioned, I would secretly allow members a bandwidth consumption of around 15MB to avoid situations like that. I would reduce usergroups to the basic ones and don't let members have multiple usergroups. In my case those would simply be: Banned and Guests (no access anyway), Unsubscribed, Subscribed, Actives and the obvious i.e. Moderators and Administrators. Because I am thinking about a subscription plan for my website. So I need to make it more valueable for members to pay a sum once in a while. I want to achieve that by giving users bandwith (or not). I have further worked on it: Code:
if($vbulletin->userinfo['usergroupid'] = 6) { $limitation = 1; } So please, if by looking over the code you find anything which doesn't match up, I hope you can help me. Cheers --------------- Added [DATE]1250419067[/DATE] at [TIME]1250419067[/TIME] --------------- As predicted, it doesn't work. When opening attachments, it will not write the quota into the database. I use the "attachment_start" hook. --------------- Added [DATE]1250431666[/DATE] at [TIME]1250431666[/TIME] --------------- Strange enough, even if I active the following plugin, all thumbnails and attachments are broken. Code:
$db->query_write(" |
Quote:
Code:
$vbulletin->db->query_write(" |
Hey thanks! =) Your code works properly.
Now I tried to stop the script from executing. I tried using die() and exit() but both did not stop the script from showing the attachment. What would I need to do in order to stop the attachment from showing up? |
exit; should stop execution of the script. Are you sure the code is actually run?
|
What I tried was to create a new plugin with hook "attachment_start" and with the simple line exit(). But still, the attachment would show up. I cleared the cache and it still showed up.
--------------- Added [DATE]1250506111[/DATE] at [TIME]1250506111[/TIME] --------------- Got it working now. Strange thing is, it will not exit the script when the thumb and attachment have been cached before? Is there a better hook for this purpose than attachment_start? --------------- Added [DATE]1250506751[/DATE] at [TIME]1250506751[/TIME] --------------- It is very strange. On my test installation, it would work with 2 pictures, it would not work with another and it would show the path to the other instead of anything else. |
Quote:
|
Yup, I have just tried around a little bit and found out that cached attachments are shown in either case.
May I ask for help on this one: Code:
$query = $db->query_read("SELECT current_bandwidth FROM " . TABLE_PREFIX . "user WHERE userid = " . $vbulletin->userinfo[userid]); |
Quote:
Code:
$asb = $vbulletin->db->query_read(" Code:
$query = $vbulletin->db->query_first(" |
Great news. You just helped me to get the script working. Here's the code:
Code:
$limit = 10000000; Also, currently, when the limit is crossed, it will show a blank attachment. Is it possible to use the space for a proper message telling the user that their bandwidth has exceeded the allowance? Simply adding a print wouldn't do the trick. |
Quote:
|
I found this article. Is it helpful to follow some of its instructions for the task that you described?
https://vborg.vbsupport.ru/showthread.php?t=98009 |
Quote:
Code:
eval(standard_error('Unable to download attachment - bandwidth allowance exceeded')); |
All times are GMT. The time now is 03:57 AM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|