vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Attachment.php (https://vborg.vbsupport.ru/showthread.php?t=220793)

rin 08-16-2009 02:08 PM

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?

Dismounted 08-17-2009 06:24 AM

exit; should stop execution of the script. Are you sure the code is actually run?

rin 08-17-2009 09:39 AM

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.

AndrewD 08-17-2009 01:03 PM

Quote:

Originally Posted by rin (Post 1869061)
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.

I imagine this is a consequence of how your browser handles files. attachment.php sends a series of browser headers, including some which allow the browser to cache the file for a year. Once those headers have been sent, you no longer have control over file delivery because it is being picked up locally and not retransmitted.

rin 08-17-2009 01:55 PM

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]);

$add = $query[current_bandwidth] + 550;

Either the mySQL query is corrupt or the value of $query[current_bandwidth] is 0. Which it should not be since it has some value in the database. My guess would be that I can not call the value via the method I used. But after searching around, also in vBulletin code I didn't find a suitable solution.

AndrewD 08-17-2009 02:27 PM

Quote:

Originally Posted by rin (Post 1869159)
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]);

$add = $query[current_bandwidth] + 550;

Either the mySQL query is corrupt or the value of $query[current_bandwidth] is 0. Which it should not be since it has some value in the database. My guess would be that I can not call the value via the method I used. But after searching around, also in vBulletin code I didn't find a suitable solution.

Reading from the database is a two-stage process, unless you are sure that there is only a single record to fetch. You either use the following sequence:

Code:

$asb = $vbulletin->db->query_read("
        SELECT current_bandwidth FROM " . TABLE_PREFIX . "user
        WHERE userid = " . $vbulletin->userinfo[userid]);
while ($query = $vbulletin->db->fetch_array($asb)) {
// process record
}

or, if you arre certain there is one record only, the following:

Code:

$query = $vbulletin->db->query_first("
        SELECT current_bandwidth FROM " . TABLE_PREFIX . "user
        WHERE userid = " . $vbulletin->userinfo[userid]);


rin 08-17-2009 02:53 PM

Great news. You just helped me to get the script working. Here's the code:
Code:

$limit = 10000000;
$query = $vbulletin->db->query_first("
        SELECT current_bandwidth FROM " . TABLE_PREFIX . "user
        WHERE userid = " . $vbulletin->userinfo[userid]);

$add = $query['current_bandwidth'] + $attachmentinfo['filesize'];

$vbulletin->db->query_write("
        UPDATE " . TABLE_PREFIX . "user
        SET current_bandwidth = $add
        WHERE userid = " . $vbulletin->userinfo[userid]
        );
if($add > $limit)
{ exit(); }

Working! One more thing I was wondering, if exiting the script like this, it will cache a blank attachment. So in case I up the limit a bit, it will not reload the actual attachment, but still show the blank one. I guess there's no easy way around this except for emptying the cache.
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.

AndrewD 08-17-2009 04:09 PM

Quote:

Originally Posted by rin (Post 1869198)
One more thing I was wondering, if exiting the script like this, it will cache a blank attachment. So in case I up the limit a bit, it will not reload the actual attachment, but still show the blank one. I guess there's no easy way around this except for emptying the cache.

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.

You need to construct and send an appropriate html error page, including non-caching headers.

rin 08-18-2009 01:23 AM

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

AndrewD 08-18-2009 04:37 AM

Quote:

Originally Posted by rin (Post 1869492)
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

You could simply try:

Code:

eval(standard_error('Unable to download attachment - bandwidth allowance exceeded'));


All times are GMT. The time now is 04:02 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
  • Page Generation 0.01028 seconds
  • Memory Usage 1,750KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (6)bbcode_code_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete