Hi, all
Owl is a excellent document management system. But
it can not support Chinese filename and fold name. The
follows is a method to support Chinese GBK charset in
filename and fold name.
In dbmodify.php, some ereg_replace will remove invalid
character in upload filename and created fold name.
Most Chinese 2 bytes character will be remove in the
expression just like the follows:
//=========================================
$new_name =
trim(ereg_replace("[^-A-Za-z0-9._[:space:]ŔŕÁáÂâĂăÄäĹĺĆćÇçČčÉéĘęËëĚěÍíÎîĎďŃńŇňÓóÔôŐőÖöŘřŮůÚúŰűÜüÝý˙()@#$\{}+,]",
"", ereg_replace("%20|^-", "_", $userfile["name"])));
//=========================================
In order to support Chinese GBK, just replace the
first ereg_replace to myereg_replace. Replace the above
to :
//=========================================
$new_name =
trim(myereg_replace("[^-A-Za-z0-9._[:space:]ŔŕÁáÂâĂăÄäĹĺĆćÇçČčÉéĘęËëĚěÍíÎîĎďŃńŇňÓóÔôŐőÖöŘřŮůÚúŰűÜüÝý˙()@#$\{}+,]",
"", ereg_replace("%20|^-", "_", $userfile["name"])));
//=========================================
Here, a user defined replace function :
myereg_replace() will be used. And myereg_replace can
be defined in the end fo file lib/owl.lib.php :
//=========================================
// for GBK charset
function myereg_replace($pattern_str, $replace_str,
$source_str)
{
$newpattern="/([-A-Za-z0-9._[:space:]()@#$\{}+,]|[\201-\376][\100-\176\200-\376])+/";
preg_match_all($newpattern, $source_str, $out,
PREG_PATTERN_ORDER);
$newname=implode($replace_str, $out[0]);
return $newname;
}
//=========================================
preg_match_all() is used to match the strings with
valid ACSII charaters and 2 bytes GBK characters, and
implode() function is used to connect the string array
to the valid string $newname.
This is about my first code in php, so please pay
attention to check the error in code. I test the
modification in Linux with Chinese support, the Chinese
words in web page is correct and in the directory
"intranet/Document" the fold name with Chinese words
has been created correctly.
The above modification in dbmodify.php, lib/readhd.php,
lib/owl.lib.php is just for the users who want to use
chinese file name in owl.