javascript - Decode Javascript packed binary data at server PHP side
问题描述
I have HTML form with 2 controls - file input control #resume and submit button #action_cv. Most of files I can (and want) upload to server are binary. There is reading and packing (encoding) this data at front side (Javascript):
function readFile(file, callback) {
let reader = new FileReader();
reader.onload = callback;
reader.readAsArrayBuffer(file);
}
$(document).ready(function () {
$('#action_cv').on('submit', function (event) {
let input_data = {
resume: null,
resume_data: null
};
let resume = null;
if (($("#resume"))[0].files.length > 0) {
resume = ($("#resume"))[0].files[0];
input_data['resume'] = resume.name;
readFile(resume, function (evt) {
let data = evt.target.result;
let bs =
String.fromCharCode.apply(null, new Uint8Array(data));
input_data['resume_data'] = bs;
});
}
// AJAX call with input_data skipped here...
})
});
Here data
contains raw binary data from file, and bs
- already packed for AJAX submission to server written by PHP. My question is very simple - how to unpack this encoded (packed) binary in PHP to get original file at server side? (No need to provide writing file operation - it seems evident)
解决方案
推荐阅读
- apache-spark-mllib - Spark ML CountVectorizer 输出说明
- c# - 访问新保存对象上的 ID 时 MongoDB C# 驱动程序 InvalidOperationException
- svg - scale SVG pathPoints
- discord - JavaScript 不工作 意外的语法错误
- drools - Drools 将不同数据类型列表传递给 drl 文件
- junit - 如何编写正确的 JUnit 测试用例休息控制器
- google-analytics - 无法将 GA360 的查看权限分配给 Google 网上论坛
- vb.net - 带有 OWIN 和 Azure 的 VB.NET 图形 API 示例
- c# - 如何正确使用 Url.Action() 在 MVC 中显示图像?
- javascript - Node.js 在另一个异步函数中嵌入一个异步函数会出错