View Full Version : Attachments show up as links if larger than a certain size.
Note: I have revised this hack to use the MySql LENGTH() function.
This hack alters the attachment view property. If the size of the attached
image is larger than a specified size, the attachment will show up as a
hyperlink as opposed to the actual image.
The size limit for the time being is hardcoded at 50000. I know I should
have made it configurable. My apologies. :( I will work on it if anyone is
interested.
This hack was requested by Fzale.
Here are the instructions on how to implement it.
In admin/functions.php, look for the following text:
if ($post[attachmentid]!=0 and $post[attachmentvisible]) {
$post[attachmentextension]=strtolower(getextension($post[filename]));
if ($post[attachmentextension]=="gif" or $post[attachmentextension]=="jpg" or $post[attachmentextension]=="jpeg" or $post[attac\
hmentextension]=="jpe" or $post[attachmentextension]=="png") {
if (($viewattachedimages) and ($bbuserinfo[userid]==0 or $bbuserinfo[showimages])) {
eval("\$post[attachment] = \"".gettemplate("postbit_attachmentimage")."\";");
} else {
eval("\$post[attachment] = \"".gettemplate("postbit_attachment")."\";");
}
} else {
eval("\$post[attachment] = \"".gettemplate("postbit_attachment")."\";");
}
} else {
$post[attachment]="";
}
And replace it with the following:
//
// Attachment size hack
//
global $DB_site;
$attachinfo=$DB_site->query_first("SELECT LENGTH(filedata) as ATTLEN from attachment where attachmentid = '$post[attachmentid]'");
if($attachinfo[ATTLEN] > 50000) {
$ok_to_watch=0;
}
else {
$ok_to_watch=1;
}
if (($ok_to_watch) and ($viewattachedimages) and ($bbuserinfo[userid]==0 or $bbuserinfo[showimages])) {
eval("\$post[attachment] = \"".gettemplate("postbit_attachmentimage")."\";");
} else {
eval("\$post[attachment] = \"".gettemplate("postbit_attachment")."\";");
}
} else {
eval("\$post[attachment] = \"".gettemplate("postbit_attachment")."\";");
}
} else {
$post[attachment]="";
}
Your feedback will be appreciated. :)
Admin
04-01-2002, 05:53 AM
Very nice. :)
Although, I think you should use LENGTH() directly in MySQL as I think it will be faster than catching the data for PHP. And, you should also do this query in showthread.php, in that huge query that gets all the info. That way you don't need to add another query for every attachment you have in the thread. Good job nonetheless! :)
Thank you for the kind words and the suggestions. :)
I feel so honored to be complimented by the great FireFly. :)
Thanks again. :)
ver nice man... now I need to make my damn attachments hack :O
Thanks neo. :)
BTW, I like the ideas of your current projects. :) I will be very interested in getting them when you are finished. :)
freakyshiat
04-02-2002, 04:26 AM
works perfect :)
thanks a bunch
freakyshiat
04-02-2002, 02:53 PM
Originally posted by FireFly
Very nice. :)
Although, I think you should use LENGTH() directly in MySQL as I think it will be faster than catching the data for PHP. And, you should also do this query in showthread.php, in that huge query that gets all the info. That way you don't need to add another query for every attachment you have in the thread. Good job nonetheless! :)
so for every attachment, its adding a query, right?
Do you have a little time to do the coding you explained? If not, its cool... :)
(Thanks again Zzed)
Ok, I revised the code to use the MySql LENGTH() function. I already tested it. Works like a charm. :)
I have already edited the original post and I have reposted the revised instructions file. ;)
freakyshiat
04-02-2002, 09:53 PM
Originally posted by Zzed
Ok, I revised the code to use the MySql LENGTH() function. I already tested it. Works like a charm. :)
I have already edited the original post and I have reposted the revised instructions file. ;)
http://forums.off-topic.net/images/smilies/bowdown.gif
freakyshiat
04-02-2002, 10:07 PM
I think it still adds another query per attachment Zzed.. but its cool for now, more than what I had before :)
I think that given the fact that not every post has an attachment, the query in showthread.php will have to make an unnecessary hit to the database for every post.
FireFly's idea to use the LENGTH() function was quite ingenious because what comes back from the query within the hack is an integer and not a block of data.
freakyshiat
05-12-2002, 06:09 PM
Originally posted by FireFly
Very nice. :)
Although, I think you should use LENGTH() directly in MySQL as I think it will be faster than catching the data for PHP. And, you should also do this query in showthread.php, in that huge query that gets all the info. That way you don't need to add another query for every attachment you have in the thread. Good job nonetheless! :)
could you tell me how do to do that? :o
Smoothie
05-12-2002, 10:32 PM
question, so if what you have set as an attachment limit on file size in your admin cp, this over rides that, and shows a link to the attached file? Say for example I have a larger file size limit set in the admin cp than what is allowed in this hack.
freakyshiat
05-13-2002, 03:19 PM
I have it set to 100k in the CP ; in the hack it is set to 50k ; so files under 50k shows up as pic, over 50k and under 100k as a link
Firefly, Help :o
i've been thinking about installing a version of this, but instead of checking the lenght every time, I was going to add a new row to the attachment table and storing the size there when the file is attached. dimensions are checked then anyway. then just check the stored value in the db when the page is loaded. would there be any down side to doing it this way?
Boofo
06-07-2002, 01:31 PM
Yes, I would be VERY intersted on making the size configurable. This is almost excatly what I have been looking for. Is there any way to maybe have it show the size of the attachment in the message itself right next to the word "Attachment"? Like in kb size? :)
Originally posted by Zzed
Note: I have revised this hack to use the MySql LENGTH() function.
This hack alters the attachment view property. If the size of the attached
image is larger than a specified size, the attachment will show up as a
hyperlink as opposed to the actual image.
The size limit for the time being is hardcoded at 50000. I know I should
have made it configurable. My apologies. :( I will work on it if anyone is
interested.
This hack was requested by Fzale.
Here are the instructions on how to implement it.
In admin/functions.php, look for the following text:
if ($post[attachmentid]!=0 and $post[attachmentvisible]) {
$post[attachmentextension]=strtolower(getextension($post[filename]));
if ($post[attachmentextension]=="gif" or $post[attachmentextension]=="jpg" or $post[attachmentextension]=="jpeg" or $post[attac\
hmentextension]=="jpe" or $post[attachmentextension]=="png") {
if (($viewattachedimages) and ($bbuserinfo[userid]==0 or $bbuserinfo[showimages])) {
eval("\$post[attachment] = \"".gettemplate("postbit_attachmentimage")."\";");
} else {
eval("\$post[attachment] = \"".gettemplate("postbit_attachment")."\";");
}
} else {
eval("\$post[attachment] = \"".gettemplate("postbit_attachment")."\";");
}
} else {
$post[attachment]="";
}
And replace it with the following:
//
// Attachment size hack
//
global $DB_site;
$attachinfo=$DB_site->query_first("SELECT LENGTH(filedata) as ATTLEN from attachment where attachmentid = '$post[attachmentid]'");
if($attachinfo[ATTLEN] > 50000) {
$ok_to_watch=0;
}
else {
$ok_to_watch=1;
}
if (($ok_to_watch) and ($viewattachedimages) and ($bbuserinfo[userid]==0 or $bbuserinfo[showimages])) {
eval("\$post[attachment] = \"".gettemplate("postbit_attachmentimage")."\";");
} else {
eval("\$post[attachment] = \"".gettemplate("postbit_attachment")."\";");
}
} else {
eval("\$post[attachment] = \"".gettemplate("postbit_attachment")."\";");
}
} else {
$post[attachment]="";
}
Your feedback will be appreciated. :)
this hacks adds an extra query per attachment :o
Sadie Frost
07-30-2002, 02:15 AM
A great idea :) Something I would like to see (and I am not complaining I swear) is to have this work for picture size in pixels. I hate seeing the horozontal scroll, but I also like to be able to view attachments. :) Just a suggestion for the future :)
Martin64
07-31-2002, 08:11 PM
Sounds like an excellent hack, but I would also like to see a "pixel" add-on for it. :)
Martin64
07-31-2002, 11:12 PM
Hmm...not good. The number of queries in showthread.php went from 24 to 37 :(
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.