Forum Moderators: coopster

Message Too Old, No Replies

Reading a file from a form.

         

Tym99

2:14 pm on Aug 9, 2006 (gmt 0)

10+ Year Member



I have an xml file that I exported from Excel. I want to take the information from the file and insert it into a database. I know how to read the data if the xml file is store on the server and I just make the filename a variable.

However, I'm going to be uploading reports once a day, and I don't want to have to keep manually removing and uploading new xml files. Nor do I really want to have to keep uploading xml files to the server via form and getting the information from there (although I could feasibley do it... I just don't want to be filling the server with files that I won't really have to use again.)

What would be ideal, is if I can have a form where I select my xml file but instead of uploading it to a server and THEN having it get the information, I'd like to bypass the uploading all together and just read the xml file in its entirety into a variable string on submit, then on my submit function it can just read the xml data and insert it into the database and no files will have to be added to the server.

Is this possible/feasible and if so can anyone give me an idea on how to do it? The XML reports aren't very large. I can't imagine a file ever being more than 20KB.

Thanks in advance!

barns101

6:51 pm on Aug 9, 2006 (gmt 0)

10+ Year Member



PHP works server side and so you can only read the file once it has been uploaded.

pixeltierra

5:23 am on Aug 10, 2006 (gmt 0)

10+ Year Member



I don't know why you're using excel to make xml for a database, I would recommend csv (comma separated values). Copy the the csv (or xml) file into the clipboard and paste it into a <textarea> form. Have php process the input by several explodes.

Tym99

2:05 pm on Aug 10, 2006 (gmt 0)

10+ Year Member



If I was using PHP4 I would have went that route and export Excel data to CSV. But with PHP5 and SimpleXML I just find it easier to read in the XML file. Getting the data from it as easy as reading data from an array.

Although pasting the XML into a text box would be a way to go. There is a discussion going on between my Team Lead and I about whether or not it would be beneficial to go ahead an upload the XML files anyway in case something happens to the database or if we should just keep the Excel reports that are sent to us on file.

pixeltierra

3:10 pm on Aug 10, 2006 (gmt 0)

10+ Year Member



That's cool about php5 and xml. I haven't had the chance to use it since I can't control that on my servers.

If your data is important to you, you should programatically backup your database regularly.