我正在尝试使用输入类型文件将aofx文件放入javascript代码中,并将其显示在屏幕上以进行财务控制。我的问题是将值与ofx分开,将其解析为xml或将其分离为json。
我最初只是尝试使用javascript,但很快我意识到我最好通过php传递它。也许我错了,如果有一种简单的方法可以做到,那么我很乐意改变。
<body>
<div class="topo">
<a style="color: white" href="">
<b>Home</b>
</a>
</div>
<div>
<div id="drop-area">
Upload OFX
<input type="file" id="upload" multiple onchange="handleFiles(this.files)">
</div>
</body>
var reader = new FileReader();
let getxml = function(path, callback){
let request = new XMLHttpRequest();
request.open("GET", path);
request.setRequestHeader("Content-Type", "text/xml");
request.onReadystatechange = function(){
if (request.readyState === 4 && request.status === 200){
callback(request.responseXML);
}
}
request.send();
}
getxml('ofxs/teste.ofx', function(xml){
console.log(xml);
})
<?php
print_r($_FILES);
$headers = array();
$charsets = array(
1252 => 'WINDOWS-1251',
);
while(!feof($_FILES)) {
$line = trim(fgets($_FILES));
if ($line === '') {
break;
}
list($header, $value) = explode(':', $line, 2);
$headers[$header] = $value;
}
$buffer = '';
// dead-cheap SGML to XML conversion
// see as well http://www.hanselman.com/blog/PostprocessingAutoClosedSGMLTagsWithTheSGMLReader.aspx
while(!feof($_FILES)) {
$line = trim(fgets($_FILES));
if ($line === '') continue;
$line = iconv($charsets[$headers['CHARSET']], 'UTF-8', $line);
if (substr($line, -1, 1) !== '>') {
list($tag) = explode('>', $line, 2);
$line .= '</' . substr($tag, 1) . '>';
}
$buffer .= $line ."\n";
}
// use DOMDocument with non-standard recover mode
$doc = new DOMDocument();
$doc->recover = true;
$doc->preserveWhiteSpace = false;
$doc->formatOutput = true;
$save = libxml_use_internal_errors(true);
$doc->loadXML($buffer);
libxml_use_internal_errors($save);
echo $doc->saveXML();
?>
我真的不知道我在做什么,我只是遵循了stackOV的一些教程和答案,然后被卡在这里。 '-'