0

I wish to create a list of XML files in a php file.

I need all my xml files to be included in my php file. I have this working see below.

<?php header('Content-type: application/xml'); echo file_get_contents("exam1.xml"); 

when I try this it works well, now I try more than one.

 <?php header('Content-type: application/xml'); echo file_get_contents("exam1.xml"); echo file_get_contents("exam2.xml"); 

it dose not read any of the files.

6
  • 1
    maybe u need to to save them in variables $var1 = file_get_contents("exam1.xml"); $var2=file_get_contents("exam2.xml"); than echo variables. also check var_dump() Commented Nov 11, 2016 at 14:15
  • Are you trying to make these files download to the browser so the user can save them or are you trying to render the contents on a page? Commented Nov 11, 2016 at 14:16
  • 1
    @devpro that's a good idea. ill try that now +`1 Commented Nov 11, 2016 at 14:19
  • @RiggsFolly ok, so i have a button onlick that shows my php page and with some js it renders some elements on a html page Commented Nov 11, 2016 at 14:22
  • So you are trying to get these xml files using AJAX? Right? Commented Nov 11, 2016 at 14:23

1 Answer 1

2

I would try passing these files back in a JSON object.

Create an array of files and then json_encode() that array.

<?php $f1 = file_get_contents("exam1.xml"); $f2 = file_get_contents("exam2.xml"); $response = array('files' => array($f1, $f2)); echo json_encode($response); ?> 

Now you will have a simple json object that you can process in the javascript and place 1 or many xml file(s) whereever you want to on the page using straight forward javascript

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.