Vtiger Customer Portal - fixing bug with file download error

Vtiger Customer Portal - fixing bug with file download error

There is a small bug in the Customer Portal - when trying to download files, an error occurs, as a result of which the user receives a file of zero size. The bug is reproduced not in all cases, but only when trying to download files with incorrect syntax in the file name. However, it can be solved by making small edits to the modules/CustomerPortal/modules/CustomerPortal/apis/DownloadFile.php file. It is this file that is responsible for finding and transferring the file you need to the Customer Portal.

So, the first thing you need to do is find the following lines in this file:

$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);

You should remove this lines and insert following:

$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'));

As a result of analyzing the problem, it turned out that this situation often arises due to problems in the file naming. Therefore, when receiving a request to download a file, we first need to check the actual file name in the file system, and not registered in the database.

We add the actual file name to the realfilename variable. Now we need to change the variable in all places of use, namely, we are looking for the following lines (around 72):

$saved_filename = $fileid."_".$filename;

$filenamewithpath = $filepath.$saved_filename;

$filesize = filesize($filenamewithpath);

$fileDetails = array();

$fileDetails['fileid'] = $fileid;

$fileDetails['filename'] = $filename;

And change it to following:

$saved_filename = $fileid."_".$filename;

$filenamewithpath = $filepath.$saved_filename;

$filesize = filesize($filenamewithpath);

$fileDetails = array();

$fileDetails['fileid'] = $fileid;

$fileDetails['filename'] = $realfilename;

After line 88 find following code:

$fileid = $attachmentDetails['attachmentsid'];

$filename = $attachmentDetails['name'];

$filepath = $attachmentDetails['path'];

And change it to this:

$fileid = $attachmentDetails['attachmentsid'];

$filename = $attachmentDetails['storedname'];

if(empty($filename)){

    $filename = $attachmentDetails['name'];

}

$filepath = $attachmentDetails['path'];

$realfilename = decode_html($attachmentDetails['name']);

And around line 100 change line:

$fileDetails['filename'] = $filename;

To this line:

$fileDetails['filename'] = $realfilename;

After carrying out these manipulations, the files from the Customer Portal must be downloaded correctly.

Popular Posts

My most popular posts

Maximum productivity on remote job
Business

Maximum productivity on remote job

I started my own business and intentionally did my best to work from anywhere in the world. Sometimes I sit with my office with a large 27-inch monitor in my apartment in Cheboksary. Sometimes I’m in the office or in some cafe in another city.

Hello! I am Sergey Emelyanov and I am hardworker
Business PHP

Hello! I am Sergey Emelyanov and I am hardworker

I am a programmer. I am an entrepreneur in my heart. I started making money from the age of 11, in the harsh 90s, handing over glassware to a local store and exchanging it for sweets. I earned so much that was enough for various snacks.

Hire Professional CRM developer for $25 per hour

I will make time for your project. Knowledge of Vtiger CRM, SuiteCRM, Laravel, and Vue.js. I offer cooperation options that will help you take advantage of external experience, optimize costs and reduce risks. Full transparency of all stages of work and accounting for time costs. Pay only development working hours after accepting the task. Accept PayPal and Payoneer payment systems. How to hire professional developer? Just fill in the form

Telegram
@sergeyem
Telephone
+4915211100235