如何将用opentype.js创建的字体保存在服务器上的文件夹中?

时间:2019-07-04 19:05:55

标签: php ajax download upload opentype

我设法用opentype.js创建字体。另外,通过下载功能下载该字体也非常有效。 但是我也需要将字体保存在服务器上的文件夹中。我试图检查像这样的下载功能:

    Font.prototype.download = function(fileName) {
        var familyName = this.getEnglishName('fontFamily');
        var styleName = this.getEnglishName('fontSubfamily');
        fileName = fileName || familyName.replace(/\s/g, '') + '-' + styleName + '.otf';
        var arrayBuffer = this.toArrayBuffer();

        if (isBrowser()) {
            window.URL = window.URL || window.webkitURL;

            if (window.URL) {
                var dataView = new DataView(arrayBuffer);
                var blob = new Blob([dataView], {type: 'font/opentype'});

                var link = document.createElement('a');
                link.href = window.URL.createObjectURL(blob);
                link.download = fileName;

                var event = document.createEvent('MouseEvents');
                event.initEvent('click', true, false);
                link.dispatchEvent(event);

            } else {
                console.warn('Font file could not be downloaded. Try using a different browser.');
            }
        } else {
            var fs = require('fs');
            var buffer = arrayBufferToNodeBuffer(arrayBuffer);
            fs.writeFileSync(fileName, buffer);
        }
    };

但是我不明白如何从中取出文件并通过ajax将其传递到服务器。有办法吗?

0 个答案:

没有答案