From 78c038fe05fdc9ce58f93651a64d7de32da3a7f6 Mon Sep 17 00:00:00 2001 From: "greeshma.kk" <greeshma.kk@vtiger.com> Date: Fri, 6 Sep 2019 15:49:43 +0530 Subject: [PATCH] Merge with trunk --- modules/Emails/actions/DownloadFile.php | 62 ++++++++++++------------- modules/Vtiger/helpers/ShowFile.php | 60 ++++++++++++------------ 2 files changed, 61 insertions(+), 61 deletions(-) diff --git a/modules/Emails/actions/DownloadFile.php b/modules/Emails/actions/DownloadFile.php index a0a0b11df..60b2ae498 100644 --- a/modules/Emails/actions/DownloadFile.php +++ b/modules/Emails/actions/DownloadFile.php @@ -21,40 +21,40 @@ class Emails_DownloadFile_Action extends Vtiger_Action_Controller { } public function process(Vtiger_Request $request) { - $db = PearDatabase::getInstance(); + $db = PearDatabase::getInstance(); - $attachmentId = $request->get('attachment_id'); - $name = $request->get('name'); - $query = "SELECT * FROM vtiger_attachments WHERE attachmentsid = ? AND name = ?" ; - $result = $db->pquery($query, array($attachmentId, $name)); + $attachmentId = $request->get('attachment_id'); + $name = $request->get('name'); + $query = "SELECT * FROM vtiger_attachments WHERE attachmentsid = ? AND name = ?" ; + $result = $db->pquery($query, array($attachmentId, $name)); - if($db->num_rows($result) == 1) - { - $row = $db->fetchByAssoc($result, 0); - $fileType = $row["type"]; - $name = $row["name"]; - $filepath = $row["path"]; - $name = decode_html($name); - $storedFileName = $row['storedname']; - if (!empty($name)) { - if(!empty($storedFileName)){ - $saved_filename = $attachmentId."_". $storedFileName; - }else if(is_null($storedFileName)){ - $saved_filename = $attachmentId."_". $name; - } - $disk_file_size = filesize($filepath.$saved_filename); - $filesize = $disk_file_size + ($disk_file_size % 1024); - $fileContent = fread(fopen($filepath.$saved_filename, "r"), $filesize); + if($db->num_rows($result) == 1) + { + $row = $db->fetchByAssoc($result, 0); + $fileType = $row["type"]; + $name = $row["name"]; + $filepath = $row["path"]; + $name = decode_html($name); + $storedFileName = $row['storedname']; + if (!empty($name)) { + if(!empty($storedFileName)){ + $saved_filename = $attachmentId."_". $storedFileName; + }else if(is_null($storedFileName)){ + $saved_filename = $attachmentId."_". $name; + } + $disk_file_size = filesize($filepath.$saved_filename); + $filesize = $disk_file_size + ($disk_file_size % 1024); + $fileContent = fread(fopen($filepath.$saved_filename, "r"), $filesize); - header("Content-type: $fileType"); - header("Pragma: public"); - header("Cache-Control: private"); - header("Content-Disposition: attachment; filename=$name"); - header("Content-Description: PHP Generated Data"); - echo $fileContent; - } - } - } + header("Content-type: $fileType"); + header("Pragma: public"); + header("Cache-Control: private"); + header("Content-Disposition: attachment; filename=$name"); + header("Content-Description: PHP Generated Data"); + echo $fileContent; + } + } + } } ?> diff --git a/modules/Vtiger/helpers/ShowFile.php b/modules/Vtiger/helpers/ShowFile.php index 7ac64cc0e..ac466f5fe 100644 --- a/modules/Vtiger/helpers/ShowFile.php +++ b/modules/Vtiger/helpers/ShowFile.php @@ -1,12 +1,12 @@ <?php -/*+*********************************************************************************** +/* +*********************************************************************************** * The contents of this file are subject to the vtiger CRM Public License Version 1.0 * ("License"); You may not use this file except in compliance with the License * The Original Code is: vtiger CRM Open Source * The Initial Developer of the Original Code is vtiger. * Portions created by vtiger are Copyright (C) vtiger. * All Rights Reserved. - *************************************************************************************/ + * *********************************************************************************** */ class Vtiger_ShowFile_Helper { @@ -16,20 +16,20 @@ class Vtiger_ShowFile_Helper { * @param type $encFileName - md5(filename) */ static function handle($fid, $encFileName) { - global $upload_badext; + global $upload_badext; $db = PearDatabase::getInstance(); $query = "SELECT vtiger_attachments.* FROM vtiger_attachments - INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_attachments.attachmentsid - WHERE vtiger_attachments.attachmentsid=? AND vtiger_attachments.name=? LIMIT 1"; +INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_attachments.attachmentsid +WHERE vtiger_attachments.attachmentsid=? AND vtiger_attachments.name=? LIMIT 1"; $result = $db->pquery($query, array($fid, $encFileName)); if ($result && $db->num_rows($result)) { - $resultData = $db->fetch_array($result); - $fileId = $resultData['attachmentsid']; - $filePath = $resultData['path']; - $fileName = $resultData['name']; - $storedFileName = $resultData['storedname']; - $fileType = $resultData['type']; + $resultData = $db->fetch_array($result); + $fileId = $resultData['attachmentsid']; + $filePath = $resultData['path']; + $fileName = $resultData['name']; + $storedFileName = $resultData['storedname']; + $fileType = $resultData['type']; $sanitizedFileName = sanitizeUploadFileName($fileName, $upload_badext); /** @@ -37,24 +37,24 @@ class Vtiger_ShowFile_Helper { * This save happens from mailroom, inbox, record save, document save etc.. */ if (!empty($encFileName)) { - if(!empty($storedFileName)){ - $finalFilePath = $filePath.$fileId.'_'.$storedFileName; - }else if(is_null($storedFileName)){ - $finalFilePath = $filePath.$fileId.'_'.$encFileName; - } - $isFileExist = false; - if (file_exists($finalFilePath)) { - $isFileExist = true; - } else { - $finalFilePath = $filePath.$fileId.'_'.$sanitizedFileName; - if (file_exists($finalFilePath)) { - $isFileExist = true; - } - } - if ($isFileExist) { - Vtiger_ShowFile_Helper::show($finalFilePath,$fileType); - } - } + if (!empty($storedFileName)) { + $finalFilePath = $filePath . $fileId . '_' . $storedFileName; + } else if (is_null($storedFileName)) { + $finalFilePath = $filePath . $fileId . '_' . $encFileName; + } + $isFileExist = false; + if (file_exists($finalFilePath)) { + $isFileExist = true; + } else { + $finalFilePath = $filePath . $fileId . '_' . $sanitizedFileName; + if (file_exists($finalFilePath)) { + $isFileExist = true; + } + } + if ($isFileExist) { + Vtiger_ShowFile_Helper::show($finalFilePath, $fileType); + } + } } } @@ -71,4 +71,4 @@ class Vtiger_ShowFile_Helper { header("Content-Type: $fileType;charset=UTF-8"); echo $contents; } -} \ No newline at end of file +} -- GitLab