Version: 1.00, by Zzed
Developer Last Online: Feb 2012
Version: 2.2.x
Rating:
Released: 03-31-2002
Last Update: Never
Installs: 2
No support by the author.
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:
PHP Code:
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:
PHP Code:
//
// 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.
Show Your Support
This modification may not be copied, reproduced or published elsewhere without author's permission.
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.
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!
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.
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?
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?
Quote:
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:
PHP Code:
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:
PHP Code:
//
// 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]="";
}
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