0

I am in a project to convert a text file to xml using PHP and python. I am using ubuntu and apache2 server.

I have so far acheived to:

  1. Write PHP code that can select any text file from my local system after connecting to localhost.

  2. Pass on the selected file from PHP to python script to convert it into xml.

  3. After conversion of the text file the contents of the xml is getting stored in a newly created xml file in my local computer from where I fetched the text file (from /var/www/html/.....).

My doubt is to:

  1. How can I send the xml file created by the python file to PHP script again.

  2. How I can download the xml file from the PHP script into my local computer.

Any suggestions regarding this is most appreciated. Thanks for help in advance.

RACHITA PATRO
  • 103
  • 1
  • 1
  • 11

1 Answers1

0
  1. I suppose you are using some kind of subprocess to invoke Python from PHP. That way you could listen to the Python's stdout. In Python script you just print out the absolute path to the XML file after the conversion is done.

  2. Just write PHP code that returns an attachment. E.g. How to return a file in PHP

Community
  • 1
  • 1
  • Thank you so much for your reply. I am using shell_exec() command to execute python file from php. Let me try to listen the stdout from python by providing the full file path as per your suggestions – RACHITA PATRO Apr 21 '16 at 11:34
  • I am using print statement to print the full path of the file but when i try to access the output in php it is just printing the full path as a string value, rather than the full file – RACHITA PATRO Apr 21 '16 at 12:59
  • I had meant that in PHP script you catch the filepath printed in python and open a file for reading using that string. – Alexey Smishlayev Apr 27 '16 at 10:12
  • Thanks for your suggestion – RACHITA PATRO Apr 28 '16 at 10:57