So a form like this:
<form action="/appapi/checkout/" method="post" mimetype="text/xml" enctype="text/xml" name="form1">
<input type="file" name="xmlfile">
<br />
<input type="submit" name="Submit" value="Submit">
</form>
Will pass me a xml file to appapi/checkout/
How can I read this file? Or do I need to save it on my server before I can read it?
Like it has been done here: receive xml file via post in php
I tried to:
$url = 'php://input';
$xml = simplexml_load_file($url);
But wouldnt work out. How can i do this?
I'm not specifically sure that enctype="text/xml" in the <form> element will make the browser to send in the file's content as raw input to the server. One might want to test if that's possible, but I don't know.
However, you could perform a standard file upload with PHPDocs and work on the temporary file that will be automatically created:
$xml = simplexml_load_file($_FILES['xmlfile']['tmp_name']);
This needs the form to have enctype="multipart/form-data". Also it's wise to first check if the file was successfully uploaded by looking into $_FILES['xmlfile']['error'], it is 0 when no error occured:
$upload = (object) $_FILES['xmlfile'];
$xml = $upload->error ? NULL : simplexml_load_file($upload->tmp_name);
BTW, the tempfile will be automatically removed when the PHP script finishes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With