-1

我正在尝试将XML文件的内容保存到 astring然后转换为JSON. 但是,我上传的文件没有被读取,file_get_contents因为它正在返回false. 我确实阅读了有关同一问题的其他帖子,但它们的文件路径是 URL。有谁知道是什么导致了这个错误?

<?php


if(isset($_POST['xml_submit'])) {
//get the xml file
$file = file_get_contents($_FILES['upload_file']['tmp_name']);
$file_string = simplexml_load_string($file);
$json = json_encode($file_string);
$json_decoded = json_decode($json, true);
//Testing if file is being read in
var_dump($file_string);



}
?>

<!-- Upload file form -->
<form class="form-horizontal" method="post" name="upload_excel" enctype="multipart/form-data">
    <fieldset>

        <div class="form-group">
            <label class="col-md-4 control-label" for="filebutton">Select File</label>
            <div class="col-md-4">
                <input type="file" name="xml" id="xml" class="input-large" accept=".xml">
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-4">
                <button type="submit" id="submit" name="xml_submit" style="color: #D96B27;border: 1px solid #D96B27" data-loading-text="Loading...">Submit</button>
            </div>
        </div>

    </fieldset>
</form>
4

1 回答 1

1

You must use $_FILES['xml']['tmp_name'].

于 2019-01-07T21:46:57.607 回答