Skip to content

Commit

Permalink
fixes #5422 BcUploadHelperで日本語ファイル名が正常に表示されない件の修正
Browse files Browse the repository at this point in the history
  • Loading branch information
sakaguchi committed Mar 17, 2014
1 parent a9fe6cc commit 9275f97
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Baser/View/Helper/BcUploadHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ public function fileLink($fieldName, $options = array()) {
if ($tmp) {
$options['tmp'] = true;
}
$fileLinkTag = $this->uploadImage($fieldName, $value, $options) . '<br /><span class="file-name">' . basename($value) . '</span>';
$fileLinkTag = $this->uploadImage($fieldName, $value, $options) . '<br /><span class="file-name">' . mb_basename($value) . '</span>';
} else {
$filePath = $basePath . $value;
$fileLinkTag = $this->Html->link('ダウンロード ≫', $filePath, array('target' => '_blank')) . '<br /><span class="file-name">' . basename($value) . '</span>';
$fileLinkTag = $this->Html->link('ダウンロード ≫', $filePath, array('target' => '_blank')) . '<br /><span class="file-name">' . mb_basename($value) . '</span>';
}
} else {
$fileLinkTag = $value;
Expand Down
17 changes: 17 additions & 0 deletions lib/Baser/basics.php
Original file line number Diff line number Diff line change
Expand Up @@ -851,3 +851,20 @@ function aa() {
}
return $a;
}

/**
* 日本語ファイル名対応版basename
*
* @param string $str
* @param string $suffix
* @return type
*/
function mb_basename($str, $suffix=null){
$tmp = preg_split('/[\/\\\\]/', $str);
$res = end($tmp);
if(strlen($suffix)){
$suffix = preg_quote($suffix);
$res = preg_replace("/({$suffix})$/u", "", $res);
}
return $res;
}

0 comments on commit 9275f97

Please sign in to comment.