6.md 3.4 KB

["ArOZ-Online Codec"]

ArOZ Online Codec

Inorder to support multiple lanuage from all around the globe, ArOZ Online System implements a new filename encoding method for all the filename and foldername that stores within the ArOZ Online System root as well as external storage directory.

This method is first used by the Upload Manager Module and it fixed the problem for upload failure of non-supported UTF-8 filename on Window host system. Hence, the filename and foldername are named as "um-file naming method" (or short for umfilename method).

UM-Filename and HexFoldername Structure

UMFilename is consists of three parts. In simple words, it is structured as follows:


where "inith" means initiate with hex.


## PHP-based Conversion
The following section explains the method for converting from and to umfilename to UTF-8 filenames.

### UTF-8 Filename to UM-Filename
Here are the method to convert a UTF-8 filename / foldername to umfilename / hexfoldername.

//Convert file $ext = pathinfo($filename, PATHINFO_EXTENSION); $fname = basename($filename, "." .$ext); $umfilename = "inith" . bin2hex($fname) . $ext;

//Convert folder $hexfoldername = bin2hex(basename($foldername));


### UM-Filename to UTF-8 Filename
To convert UMfilename back into UTF-8 filename, you will need to use the folowing code segments for this purpose.

//Convert file if (substr(basename($filename),0,5) === "inith"){

$ext = pathinfo($filename, PATHINFO_EXTENSION);
$orgname = str_replace("inith","",basename($filename,"." . $ext));
if (ctype_xdigit($orgname) && strlen($orgname) % 2 == 0) {
    $orgname = hex2bin($orgname);
}
$decodedName = dirname($filename) . "/" . $orgname . "." . $ext;

}

//Convert folder if (ctype_xdigit($foldername) && strlen($foldername) % 2 == 0) {

$decodedName = hex2bin($foldername);

}


## Javascript Based Conversion
Since later stage of the Beta phrase, Javascript based umfilename decoding is also supported with the ```ao_module_codec``` class in ao_module wrapper. To use them, simply include the wrapper and call the functions below.

ao_module_codec.decodeUmFilename(umfilename_here);

ao_module_codec.decodeHexFoldername(hexFolderName_here); ```

Be noted that ao_module wrapper do not support encoding. You should avoid performing um-file encoding on the client side as well as the original aim for umfilename system is to fix localization issue on server side.

UMfilename HexFoldername in File Explorer

UMFilename and HexFoldername are shown with human-readable format while presented on the File Explorer build into ArOZ Online System.

For files that is encoded as umfilename or hexfoldername in the background Linux file system (or Windows NTFS if you are hosting the system on Windows), the background color of that particular file will be updated to its respective color. The color coding scheme is as follow.

File Naming Method Encode Method Represent Color
Default (UTF-8) None White
UM-Filename "inith" + bin2hex({original_filename}) + "." + {original_ext} Blue
HEX-Foldername bin2hex({original_foldername}) Green

Conversion using fsconv

Please refer to the File Systen API for how to use the fsconv to convert filenames that is encoded with AO-Codec.