Parsing a client-provided file with PHP with(out?) uploading - php

I am currently working on a web page that should do the following. As a little background, we are working on uploading a bunch of data that has a decent level of user-errors in the cell formatting to a database.
The data is stored in Excel spreadsheets. The spreadsheets are formatted in the same way, (99.9% of the time) but occasionally there are some wonky values within the cells themselves. Here is my goal: I would like the user to be able to
1) Provide the excel file to the page
2) Parse the file with PHP, then send the newly extracted data to a table on the page with editable cells
3) The user can see what came out of their file, then correct it for any slight errors before choosing to send the extracted data to the database.
I can do steps 2 and 3 using PHPExcel with a test file stored on the server, but I am having trouble getting from step 1 to step 2. My vision is to have the user specify the Excel spreadsheet and do the parsing without leaving the current page and losing the data in the fields. I would really like to keep the page from changing, as there are additional text fields on the page and I actually have to parse TWO spreadsheets before the data is taken from all of the fields and sent off to the database.
I guess I'm wondering if there's a way to use a client-provided file in PHP without doing a POST to upload. OR if there's a way to upload the file and have it parsed without leaving the page. I'm new to web development, so excuse me if those last few sentences made absolutely no sense.
Any thoughts?

PHP cannot do a single thing to the file until it is uploaded to the server. You could put a file upload form in an iframe and do some AJAX-y thing as described here.
As for handling PHP file uploads, the docs have a whole section.

Related

Fill pdf form and insert image, without Pdftk

is there any possible way to not lose any content, when inserting an image into a filled pdf, i am using the fpdm.php script from here and works prettty good i might add. the pdfs i am using i pass them trough pdftk, as in pdftk.exe insert.pdf output output.pdf so they can be filled via php with out throwing errors
so my problem is this, i have a pdf template, which i use to fill it with an array passed from php, and output it to browser or server, and works ok, but when i try to insert an image into it, it inserts it, but loses all filled data, i need to retain that data. i cant use pdftk because im on a godaddy shared hosting plan, also setasign scripts works i know, but i am trying to find a way without buying anything yet.
i found this stamper which stamps ok but loses pdf data, all boxes get blanked, and also this one that places the image and loses all data too. setasign is doing some magic stuff right there
All mentioned scripts are using FPDI in the background which simply doesn't modifes the original document but will allow you to recreate a completely new PDF document by importing another one page by page into reuseable structures (XObjects). Because form fields or other dynamic content like links or any other annotation type are not part of a pages content stream they will get lost.
The mentioned "magic" of the SetaPDF products is, that they modify the original document. Because of this all content will retain.

HTML with JScript to read/write XLS file

Very sorry if this is not in the right place etc. I have been researching this for a while but its raised more questions!
I have developed a spreadsheet which I use to set a teams duties for a shift. There are 5 teams, each with staff which can change day to day.
the spreadsheet works fine, but its too complicated for some users. I am therefore trying to develop a straightforward web based form.
All the data is on the spreadsheet, held on a network drive (essentially locally).
I need to be able to have several combo/select boxes which get their values from a range of cells from the XLS. Along with the ability to output the final selections to a XLS sheet.
Finally, it needs to be able to load the previous day values on load.
What is the best way of developing a web page for this? Is Jscript the best option? Can I access a local file with jScript?
Thanks in advance
Adrian
The easiest option for you is to use google web forms. These allow creation of forms that will submit data to a google spreadsheet. Which is essentially an uploaded version of your local spreadsheet and can be downloaded to excel.
In case if you want more control and programming, pure javascript cant play with files, you need server side too. Javascript is not necessary unless you want to make your app do some visually fancy stuff. Since you mentioned php as a tag of this question, it seems you are a bit familiar with php. The task you have mentioned can be done using php programming as below:
Read excel file using an excel plugin
Parse relevant data using a text matching function, may require regular expressions knowledge.
display the form by building up the html and putting in the variables using the data obtained above.
Write a method to save the data submitted by the form to the same excel file using the excel plugin.
As its not convenient to play around with excel files. A better option would be to generate csv file or use a database using a database class . csv files can be parsed easily using text.

Where should I display or store data that is imported from a file?

When I do an import of data from a file, such as csv or text file, I would like to display on a summary page (table view) about what is going to be imported to the database, and user can select or deselect what will be imported into the database. I would like to find out what is the best way of temporary storing these data to be displayed onto the summary page?
To give a clearer understanding about what i am talking about, for example:
I have a csv file that holds a list of products.
I would do an importation to read the csv file and display onto a summary page with
table view and checkboxes to select/deselect some of the data.
After the selection, I would click the confirm button to store those checked data
So between the process of getting the csv data to the summary page for display, where should I store the data, in the database as a tbl_temp data and clean off when done, or just read directly from the csv file?
Thanks.
I would think an array would do the trick unless you think your environment is really unstable or, for user interface reasons, then just store to a temp file. Temp db table seems a bit much.
I would just display it in the browser, and stored? It's already stored, the uploaded CSV file!
Unless you don't run into an actual problem with that approach, why care?
Just use HTML to display the data read from the file in a web browser. Use standard HTML Form and form controls. Use PHP scripting logic to control what happens when the form is submitted. You could have the submit button hand off to a service or some other php file that could handle writing it to the db.
Why bother writing to a temp table, to just read back out and display in a form to be then written back to a perm. table.
If this were a process that you would be performing a lot, i might give it a little more consideration.

Advice on posting JavaScript generated content to a file for download as CSV

I have some user specific JavaScript generated content I want to post to the server to generate a CSV file that the user can then download.
I have in mind to follow the guidance under Option 3.1 of the jQuery Table to CSV Plugin but the following occurs to me…
What if 2 or more users are concurrently on the page and using the same functionality? If a generic URL is used for the CSV file (as kunalbabre suggests) is it not possible then that they end up downloading each other's data?
Presumably one should therefore generate a unique URL for the CSV? If so, what methods are best?
Any advice much appreciated.
No. The CSV is generated dynamically in response to the request. The only file on the server is the PHP program. The CSV file doesn't exist until the browser receives the response and saves it to a file.

PHP make real time stock exchange application

I have a software which give me stock data as excel format , the data is automatically update continuously in every second.i have to show these data in web page such like they are shw in excel (ie the web data should be also update in such manner ) and these data. how it is be done.
Programatically export the data into CSV format and import it into a relational database.
Extract the data with web language and display in webpage. Tutorials for these steps should all be available.
To convert from xls to csv see the question...
converting an Excel (xls) file to a comma separated (csv) file without the GUI
For the second part, you can have a cron job run a PHP script that reads in the csv file contents and inserts this into a database. Plenty of threads on this also.
To display, select from database and format appropriately, can follow any of the basic tuts on the net for this part.
Post your code if you get stuck :)
As you've been told, use PHPExcel to read Excel file.
However, refreshing data every second is gonna make a very heavy load on your server.
I'd recommend you rather use server side push using Comet technologies. Take a look at Meteor server.
You will accomplish 'persistent' connection, so server will push data to the client, and the need to refresh the page or create ajax request every second will be gone.
You've tagged this PHP, so I assume that's your scripting language of choice: use PHPExcel to read the Excel file and write it out as formatted HTML to your web page. PHPExcel's HTML Writer will retain all the style and formatting of the original Excel workbook.
However, an update every second is pretty extreme for a web page, and for a scripting language. Rather than reading the Excel file whenever the page is requested, run this as a background task converting the Excel to a static HTML file whenever an Excel file is received, and serve the latest static HTML.
If this extreme timing is needed, then you might be better looking at a compiled language, or even a non-web solution.

Categories