Chinese File Name Handling

Replace file name with Chinese characters:

$result = $this->competition_upload($member_id, 'file_pdf', 'pdf');

			//Replace name with member name and work title
			$file = $result['file'];
			$ext = $this->upload_handler->get_extension($file);
			$file_name = $this->member->name . '_' . $title . '.' . $ext;
			$file_name_big5 = iconv('UTF-8','Big5',$file_name);
			$this->upload_handler->rename_file($file, $file_name_big5);

			$data['pdf'] = dirname($result['file_url']) . '/' . $file_name;

Uploading Chinese file to both windows and Linux server works, but the problem is to download it. Codeigniter doesn’t allow Chinese character in URL (URI) even I made some changes to config.php and extend URI.php (Core).

To download Chinese files, to use ZIP class is a good solution. File name could be changed when adding it to archive.



Sample Code:

$file = FCPATH . 'uploads\members\1\competition_2014\test.pdf';
$zip = new ZipArchive;
$open = $zip->open('', ZipArchive::CREATE);
if ($open === TRUE) {
    $zip->addFile($file, iconv('utf-8', 'big5', '雷克斯_劇本名.pdf'));
    echo 'ok';
} else {
    echo 'failed: ' . $open;