Filename encoding problem

Topics: Developer Forum
Jul 10, 2009 at 2:53 PM


I am using following generated filenames:

$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);

Variable $description is string (utf8) and is shown regurarly in browser ("žluté portfolio"). But when I save it as filename, there is encoding problem with this filename ("ĹľlutĂ© portfolio").

Thank you for your help...

Jul 11, 2009 at 4:13 AM

Based on the result, it looks like the operating system expects Windows-1250 rather than UTF-8.

Try to save your PHP-script in UTF-8 (without BOM) and encode the filename in Windows-1250 as follows:


$description = mb_convert_encoding('žluté portfolio', 'CP1250', 'UTF-8');
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);

I have not tried to save Unicode filenames myself, but according to comment by tony2001 at php dot net

"PHP doesn't care if it's Unicode or not, it just passes the filename to
the OSes filesystem func and if it fails - we can do nothing about it.

I take this as a statement that such PHP-scripts are not portable and that you need to use for the filename the character encoding expected by the operating system on the particular server where PHP is running.