Files
fonteditor/demo/sync/font.php
2015-04-12 23:36:15 +08:00

46 lines
1.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
header('Content-Type: application/javascript');
function callback($data) {
echo json_encode($data);
}
function writeFile($base64Str, $outputfile) {
$ifp = fopen($outputfile, "wb");
fwrite($ifp, base64_decode( $base64Str));
fclose($ifp);
return($outputfile);
}
function main() {
$fontName = $_POST['fontName']; // 字体名字
$fontType = $_POST['fontType']; // 字体类型,多个类型用`,`隔开
$encode = $_POST['encode']; // 编码,默认base64
if (empty($fontName)) {
callback(array(
status => 1,
statusInfo => '没有同步的字体名!'
));
return;
}
$count = 0;
if (empty($encode) || $encode === 'base64') {
foreach (explode(',', $fontType) as $type) {
if (!empty($_POST[$type])) {
writeFile($_POST[$type], $fontName.'.'.$type);
$count++;
}
}
}
callback(array(
status => 0,
statusInfo => 'sync '.$count.'font files.'
));
}
main();