Skip to content
Snippets Groups Projects
Commit 6a406e57 authored by Uma's avatar Uma
Browse files

Fixes #1511 Portal Download files results on zero length file

parent 4ef07f9c
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -63,18 +63,22 @@ class CustomerPortal_DownloadFile extends CustomerPortal_API_Abstract {
$fileres = $adb->pquery($fileidQuery, array($id));
$fileid = $adb->query_result($fileres, 0, 'attachmentsid');
$filepathQuery = 'SELECT path,name FROM vtiger_attachments WHERE attachmentsid = ?';
$fileres = $adb->pquery($filepathQuery, array($fileid));
$filepath = $adb->query_result($fileres, 0, 'path');
$filename = $adb->query_result($fileres, 0, 'name');
$filename = decode_html($filename);
$filepathQuery = 'SELECT path,name,storedname FROM vtiger_attachments WHERE attachmentsid = ?';
$fileres = $adb->pquery($filepathQuery, array($fileid));
$filepath = $adb->query_result($fileres, 0, 'path');
if($adb->query_result($fileres, 0, 'storedname')) {
$filename = $adb->query_result($fileres, 0, 'storedname');
} else {
$filename = $adb->query_result($fileres, 0, 'name');
}
$realfilename = decode_html($adb->query_result($fileres, 0, 'name'));
$saved_filename = $fileid."_".$filename;
$filenamewithpath = $filepath.$saved_filename;
$filesize = filesize($filenamewithpath);
$fileDetails = array();
$fileDetails['fileid'] = $fileid;
$fileDetails['filename'] = $filename;
$saved_filename = $fileid."_".$filename;
$filenamewithpath = $filepath.$saved_filename;
$filesize = filesize($filenamewithpath);
$fileDetails = array();
$fileDetails['fileid'] = $fileid;
$fileDetails['filename'] = $realfilename;
$fileDetails['filetype'] = $filetype;
$fileDetails['filesize'] = $filesize;
$fileDetails['filecontents'] = base64_encode(file_get_contents($filenamewithpath));
......@@ -86,8 +90,13 @@ class CustomerPortal_DownloadFile extends CustomerPortal_API_Abstract {
//construct path for attachment and get file size and type details
$attachmentDetails = $rawAttachmentDetails[0];
$fileid = $attachmentDetails['attachmentsid'];
$filename = $attachmentDetails['name'];
$filename = $attachmentDetails['storedname'];
if(empty($filename)){
$filename = $attachmentDetails['name'];
}
$filepath = $attachmentDetails['path'];
$realfilename = decode_html($attachmentDetails['name']);
$saved_filename = $fileid."_".$filename;
$filenamewithpath = $filepath.$saved_filename;
$filesize = filesize($filenamewithpath);
......@@ -96,7 +105,7 @@ class CustomerPortal_DownloadFile extends CustomerPortal_API_Abstract {
//Construct array with all attachment details
$fileDetails = array();
$fileDetails['fileid'] = $fileid;
$fileDetails['filename'] = $filename;
$fileDetails['filename'] = $realfilename;
$fileDetails['filetype'] = $filetype;
$fileDetails['filesize'] = $filesize;
$fileDetails['filecontents'] = base64_encode(file_get_contents($filenamewithpath));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment