[Vtigercrm-commits] [vtiger-commits] r4811 - in /vtigercrm/trunk: include/RelatedListView.php include/utils/CommonUtils.php modules/uploads/downloadfile.php

vtigercrm-commits at vtiger.fosslabs.com vtigercrm-commits at vtiger.fosslabs.com
Fri Mar 31 03:12:55 EST 2006


Author: saraj
Date: Fri Mar 31 01:12:48 2006
New Revision: 4811

Log:
* Modified to make attachment work properly

Modified:
    vtigercrm/trunk/include/RelatedListView.php
    vtigercrm/trunk/include/utils/CommonUtils.php
    vtigercrm/trunk/modules/uploads/downloadfile.php

Modified: vtigercrm/trunk/include/RelatedListView.php
==============================================================================
Binary files - no diff available.

Modified: vtigercrm/trunk/include/utils/CommonUtils.php
==============================================================================
--- vtigercrm/trunk/include/utils/CommonUtils.php (original)
+++ vtigercrm/trunk/include/utils/CommonUtils.php Fri Mar 31 01:12:48 2006
@@ -1411,6 +1411,29 @@
 	}
 }
 
+/**
+ * This function is used to get the File Storage Path in the server.
+ * @param int $attachmentid - file attachment id ie., crmid of the attachment
+ * @param string $filename  - file name
+ * return string $filepath  - filepath inwhere the file stored in the server will be return
+*/
+function getFilePath($attachmentid,$filename)
+{
+	global $adb;
+	global $root_directory;
+
+	$query = 'select crmid, setype, smownerid, users.user_name from crmentity inner join users on crmentity.smownerid=users.id where crmid='.$attachmentid;
+	$res = $adb->query($query);
+
+	$user_name = $adb->query_result($res,0,'user_name');
+
+	if(is_file($root_directory.'storage/user_'.$user_name.'/attachments/'.$filename))
+		$filepath = $root_directory.'storage/user_'.$user_name.'/attachments/';
+	else
+		$filepath = $root_directory.'test/upload/';
+
+	return $filepath;
+}
 
 
 

Modified: vtigercrm/trunk/modules/uploads/downloadfile.php
==============================================================================
--- vtigercrm/trunk/modules/uploads/downloadfile.php (original)
+++ vtigercrm/trunk/modules/uploads/downloadfile.php Fri Mar 31 01:12:48 2006
@@ -15,34 +15,31 @@
 global $adb;
 global $fileId;
 
-$fileid = $_REQUEST['fileid'];
-
-//$dbQuery = "SELECT * from seattachmentsrel where crmid = '" .$fileid ."'";
-//$attachmentsid = $adb->query_result($adb->query($dbQuery),0,'attachmentsid');
-$attachmentsid = $fileid;
+$attachmentsid = $_REQUEST['fileid'];
+$entityid = $_REQUEST['entityid'];
 
 $returnmodule=$_REQUEST['return_module'];
 
-if($_REQUEST['activity_type']=='Attachments')
-	$attachmentsid=$fileid;
-
-$dbQuery = "SELECT * FROM attachments ";
-$dbQuery .= "WHERE attachmentsid = " .$attachmentsid ;
+$dbQuery = "SELECT * FROM attachments WHERE attachmentsid = " .$attachmentsid ;
 
 $result = $adb->query($dbQuery) or die("Couldn't get file list");
 if($adb->num_rows($result) == 1)
 {
 	$fileType = @$adb->query_result($result, 0, "type");
 	$name = @$adb->query_result($result, 0, "name");
-	$fileContent = @$adb->query_result($result, 0, "attachmentcontents");
-	$size = @$adb->query_result($result, 0, "attachmentsize");
+
+	$filepath = getFilePath($attachmentsid,$name);
+	$filesize = filesize($filepath.$name);
+	$fileContent = fread(fopen($filepath.$name, "r"), $filesize);
+
+	$org_filename = ltrim($name,$entityid.'_');
 
 	header("Content-type: $fileType");
-	//header("Content-length: $size");
+	header("Content-length: $filesize");
 	header("Cache-Control: private");
-	header("Content-Disposition: attachment; filename=$name");
+	header("Content-Disposition: attachment; filename=$org_filename");
 	header("Content-Description: PHP Generated Data");
-	echo base64_decode($fileContent);
+	echo $fileContent;
 }
 else
 {





More information about the vtigercrm-commits mailing list