Page 1 of 1

[MODDB] No Double Attachments (for AttachMOD)

Posted: Mon Jun 21, 2004 3:19 pm
by fredol
Hi,

This is just a few changes to the great MOD that is AttachMOD so users will not be able to send the same file twice...

To do so, when sending an attachment the MD5hash of the file will be calculated (using md5_file) and compared to others already posted, and if the same one (so same file) is found then the file is deleted and an error message tells user that the file has already been posted!

To work you'll need to alter ATTACHMENTS_DESC_TABLE to store MD5hashes, and this means that the checking will only be working with files posted AFTER this MOD has been installed... but if you're interrested I could try to do a little thing that will calculates all MD5hashes for attachments posted before....

IMPORTANT!!
> You need at least PHP 4.2.0 to be able to use this - if you have an earlier version of PHP then DO NOT INSTALL THIS MOD, it won't work (since the md5_file function doesn't exists!)
> I haven't tested it with using ftp, it might not work!! (Please if you've tested it tell me if it works or not, thanks!)

Code: Select all

############################################################## 
## MOD Title: No Double Attachments (for AttachMOD)
## MOD Author: fredol < fredol@lovewithsmg.com > (fredol) N/A
## MOD Description: This will adds MD5 calculation/checking when an attachment is
##	posted/upgraded, and if the same file (same hash) is already in the database
##	then the file will be deleted, telling user that the file has already been
##	posted (to avoid same file posted twice)
## MOD Version: 1.0.0
## 
## Installation Level: Easy
## Installation Time: 1 Minute (less with the great EasyMOD! :-)
## Files To Edit:	attach_mod/posting_attachments.php
##			language/lang_english/lang_main_attach.php
## Included Files: n/a 
############################################################## 
## For Security Purposes, Please Check: http://www.phpbb.com/mods/ for the 
## latest version of this MOD. Downloading this MOD from other sites could cause malicious code 
## to enter into your phpBB Forum. As such, phpBB will not offer support for MOD's not offered 
## in our MOD-Database, located at: http://www.phpbb.com/mods/ 
############################################################## 
## Author Notes:
##	Just a few changes to the great MOD that is AttachMOD ; MD5 hash will be calculated when
##	an attachment is posted/upgraded, and if the same file (same hash) is already in the database
##	when the file will be deleted, telling user that the file has already been posted (to avoid
##	same file posted twice)
##
##	To work you'll need to alter ATTACHMENTS_DESC_TABLE to store MD5hashes, and you need to have 
##	at least PHP 4.2.0 (if you have an earlier version of PHP then DO NOT INSTALL THIS MOD, it won't
##	work (since the md5_file function doesn't exists!)
##
##	IMPORTANT:
##	- You need PHP 4.2.0 or above to be able to use this MOD!!
##	- I haven't tested it with using ftp, it might not work!! (Please if you've tested it tell me if
##	  it works or not, thanks!)
##
##	And many Thanks & Congratulations to Acyd Burn for his amazing great work!! :D
##
############################################################## 
## MOD History: 
## 
##   2004-06-30 - Version 1.0.0 
##	- Submitted to the MOD-DB (no changes were made)
##	- Renamed to: No Double Attachments
##
##   2004-06-21 - Version 0.0.1 
##	- First version, should work just fine ;) 
## 
############################################################## 
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD 
############################################################## 


# 
#-----[ SQL ]----- 
# 
# Note: Change phpbb_ to your prefix!!!
ALTER TABLE `phpbb_attachments_desc` ADD `MD5hash` VARCHAR( 50 ) NOT NULL ;
# 
#-----[ OPEN ]----- 
# 
attach_mod/posting_attachments.php
# 
#-----[ FIND ]----- 
#
#Note: full line is longer
					$sql = "INSERT INTO " . ATTACHMENTS_DESC_TABLE . " (physical_filename
# 
#-----[ BEFORE, ADD ]----- 
#
					$MD5hash = md5_file($upload_dir . '/' . $this->attachment_list[$i]);
# 
#-----[ IN-LINE FIND ]----- 
#
)
# 
#-----[ IN-LINE BEFORE, ADD ]----- 
# 
, MD5hash
# 
#-----[ FIND ]----- 
#
					VALUES ( '" . $this->attachment_list[$i] . "
# 
#-----[ IN-LINE FIND ]----- 
#
)";
# 
#-----[ IN-LINE BEFORE, ADD ]----- 
# 
, '$MD5hash'
# 
#-----[ FIND ]----- 
#
#Note: full line is longer
				$sql = "INSERT INTO " . ATTACHMENTS_DESC_TABLE . " (physical_filename
# 
#-----[ BEFORE, ADD ]----- 
#
					$MD5hash = md5_file($upload_dir . '/' . $this->attach_filename);
# 
#-----[ IN-LINE FIND ]----- 
#
)
# 
#-----[ IN-LINE BEFORE, ADD ]----- 
# 
, MD5hash
# 
#-----[ FIND ]----- 
#
				VALUES ( '" . $this->attach_filename . "
# 
#-----[ IN-LINE FIND ]----- 
#
)";
# 
#-----[ IN-LINE BEFORE, ADD ]----- 
# 
, '$MD5hash'
# 
#-----[ FIND ]----- 
#
#Note: in function move_uploaded_attachment
		global $error, $error_msg, $lang, $upload_dir;
# 
#-----[ IN-LINE FIND ]----- 
#
;
# 
#-----[ IN-LINE BEFORE, ADD ]----- 
#
, $db
# 
#-----[ FIND ]----- 
#
		if ( (!$error) && ($this->thumbnail == 1) )
# 
#-----[ BEFORE, ADD ]----- 
# 
		if (!$error)
		{
			$MD5hash = md5_file($upload_dir . '/' . $this->attach_filename);
			$sql = "SELECT attach_id FROM " . ATTACHMENTS_DESC_TABLE . " WHERE MD5hash = '$MD5hash'";
			if ( !($result = $db->sql_query($sql)) )
			{
				message_die(GENERAL_ERROR, 'Could not get existing attachments information', '', __LINE__, __FILE__, $sql);
			}
			if ($db->sql_numrows($result) > 0)
			{
				unlink($upload_dir . '/' . $this->attach_filename);
				//
				$error = TRUE;
				if(!empty($error_msg))
				{
					$error_msg .= '<br />';
				}
				$error_msg .= $lang['Attachment_already_exists'];
				return;
			}
		}

# 
#-----[ OPEN ]----- 
#
language/lang_english/lang_main_attach.php
# 
#-----[ FIND ]----- 
#
$lang['General_upload_error'] = 'Upload Error: Could not upload Attachment to %s.'; // replace %s with local path
# 
#-----[ AFTER, ADD ]----- 
# 
$lang['Attachment_already_exists'] = 'Sorry but this file has already been posted!';
# 
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------ 
# 
# EoM 
Hope you'll like it 8)
fredol

Posted: Mon Jun 21, 2004 4:35 pm
by »»EDDY««
Cool MOD!

Posted: Sun Jun 27, 2004 10:51 am
by FX
Exellent mod. 8) Very easy to install :D

Posted: Sun Jun 27, 2004 12:05 pm
by fredol
Thanks! :mrgreen: 8)

fredol

Posted: Sat Aug 21, 2004 10:33 pm
by wGEric
MOD is now in the database and can be found here
http://www.phpbb.com/phpBB/viewtopic.php?t=206851

Locked.