howto : Drupal CJK filename dropped.

Submitted by 바라미 on 일, 11/16/2008 - 11:37

reason : Drupal is using basename() function on filename extracting. But basename function with php5 is not safe locale. If you use utf-8 encoding on cjk like charset, basename will not work exatly.

solution : First. don't use php5, and use php4.
Second. make locale indepent basename function (ex: drupal_basename() )

function drupal_basename($path,$prefix = '') {
$path = preg_replace('|^.+[\\/]|', '', $path);

if ($prefix) {
$path = preg_replace('|'. preg_quote($prefix) .'$|', '', $path);
}
return $path;
}

I changed pattern '|^.+[\\/]|' to '/([^\/]+)\//'.


function drupal_basename($path,$suffix = '') {
$path = preg_replace('/([^\/]+)\//', '', $path);

if ($suffix) {
$path = preg_replace('/'.preg_quote($suffix).'$/', '', $path);
}
return $path;
}

And replace three files to use drupal_basename function.
* file.inc
* common.inc
* locale.inc

Reference : http://drupal.org/node/278425

댓글 달기

Restricted HTML

  • 사용할 수 있는 HTML 태그: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • 줄과 단락은 자동으로 분리됩니다.
  • Web page addresses and email addresses turn into links automatically.