kartik-v / yii2-export

A library to export server/db data in various formats (e.g. excel, html, pdf, csv etc.)
http://demos.krajee.com/export
Other
165 stars 126 forks source link

Sanitize file names in a better way #330

Closed lubobill1990 closed 3 years ago

lubobill1990 commented 4 years ago

https://github.com/kartik-v/yii2-export/blob/29fc213889ad805f5e8f5574404c5341726343e9/src/ExportMenu.php#L802 Hi @kartik-v ,

If I don't specify the filename, using the default translation, there will be a php notice: iconv(): Detected an illegal character in input string

image

Besides, may I ask why iconv from UTF-8 to ISO-8859-1//TRANSLIT is needed here?

Mohsen6558 commented 3 years ago

on Persian language too I change code to: $filename = iconv("UTF-8", "ISO-8859-1//TRANSLIT", utf8_encode($this->filename)); from $filename = iconv("UTF-8", "ISO-8859-1//TRANSLIT", $this->filename);

kartik-v commented 3 years ago

The reason iconv exists is because PHP Spreadsheet does not accept weird characters in filename. You need to supply the utf8 encoded filename as parameter to yii2-export so that iconv works well especially if your filename has non Ascii characters.

@Mohsen6558 - you should not change that in the library procedure - but do this at your ExportMenu widget level. For example you folks can try this:

echo ExportMenu::widget([
   'filename' => utf8_encode('YOUR_SPECIAL_CHARACTERS_FILENAME')
]);

However, I will check if I can provide an enhancement to better handle this.

kartik-v commented 3 years ago

Resolved via above commit.