, mb_detect_encoding(), .
, SJIS. SJIS, Windows SJIS .
. File, , SJIS, Response::file(). .
public function download(){
if($this->Auth->user()){
$pNewsObj = ClassRegistry::init('PublicNews');
$news = $pNewsObj->findById($newsId);
if (!$news) {
throw new NotFoundException();
}
$fileName = mb_convert_encoding($news['PublicNews']['reference'], 'SJIS-win', 'UTF8');
if (strpos($fileName, '..') !== false) {
throw new ForbiddenException();
}
$filePath = WWW_ROOT . 'upload_news' . DS . $fileName;
if (!is_readable($filePath)) {
throw new NotFoundException();
}
if (function_exists('mime_content_type')) {
$type = mime_content_type($filePath);
$this->response->type( $type );
} else {
}
$this->response->download( $fileName );
$this->response->body( file_get_contents($filePath) );
return $this->response;
}else{
return $this->redirect(array('controller'=> 'users', 'action' => 'login'));
}
}
SJIS UTF8, . SJIS . SJIS ascii . (\). , 表 (955C) (5C = ). , .表 .十 , - 10.能 , .
UTF-8, SJIS, . explode() SJIS. strpos() .
FTP SCP? , SJIS UTF-8 UTF-8 SJIS .