wangsisi 发表于 2011-12-29 10:53:28

修改mediawiki上传文件时文件名含有中文的乱码问题

wamp环境下,mediawiki上传文件的文件名含有汉字时,上传到服务器存储的文件名是乱码,下面是解决办法:
(参考:http://d.hatena.ne.jp/akaiwa/20080604/1212590583)
修改mediawiki/includes/filerepo/FSRepo.php文件:
function publishBatch( $triplets, $flags = 0 )函数中
        $dstPath = "{$this->directory}/$dstRel";
        $archivePath = "{$this->directory}/$archiveRel";

        //fix bug while upload file with chinese character in filename
        $dstPath = mb_convert_encoding( $dstPath, 'GBK', 'auto');
        $archivePath = mb_convert_encoding( $archivePath, 'GBK', 'auto');

        // Archive destination file if it exists
        if( is_file( $dstPath ) ) {function deleteBatch( $sourceDestPairs )函数中foreach ( $sourceDestPairs as $pair ) {
        list( $srcRel, $archiveRel ) = $pair;
        $srcPath = "{$this->directory}/$srcRel";
        $archivePath = "{$this->deletedDir}/$archiveRel";

        //fix bug while upload file with chinese character in filename
        $srcPath = mb_convert_encoding( $srcPath, 'GBK', 'auto');
        $archivePath = mb_convert_encoding( $archivePath, 'GBK', 'auto');

        $good = true;function getFileProps( $virtualUrl )函数中
        function getFileProps( $virtualUrl ) {
        $path = $this->resolveVirtualUrl( $virtualUrl );
        //fix bug while upload file with chinese character in filename
        return File::getPropsFromPath( mb_convert_encoding( $path, 'GBK', 'auto') );
        //original code
        //return File::getPropsFromPath( $path );
}
页: [1]
查看完整版本: 修改mediawiki上传文件时文件名含有中文的乱码问题

美国HostEase虚拟主机一年198元