tags:

views:

605

answers:

3

I am working on a database program using PHP to keep track of the products we manage at my workplace.

For this project, I need to be able to select an .XLS file which contains new product data. New data consists of the following fields:

Type CHAR(3), Line CHAR(2), Number INT, Measure INT, Comments VARCHAR(255), Variation CHAR(1) i.e.('Y' || 'N')

These files are created in Excel, or Google Docs; I have found a wonderful excel_reader which allows me to extract the values from this file.

As this is an action which will happen routinely, as new products are created, so I do not want the file to be stored in my server directory (after a while there would be dozens!). I would rather that the file simply be read, because the import script I'm writing transfers the file's data into an array.

What I really want to happen is to have the user select the file's location (on their local computer) through an HTML form, and then have the script save that file's contents to a MySQL database without ever sending the file to the Server.

I would greatly appreciate any advice you can offer me, I'm not even sure that my plan is a valid way to handle this situation.

+6  A: 

It will have to be stored, at least temporarily. Delete the file after you have what you need from it (presumably after moving it out of the temp directory using move_uploaded_file, to the folder from which you will read it), then remove it using unlink.

As a last point, I would be a little worried about immediate deletion of uploaded files. What if something goes wrong with the script while the file is being parsed and data stored in the database? It would probably be a good idea to have a cron job that periodically deletes the files, to be on the safe side, instead of deleting them immediately.

karim79
I'm never fast enough on this site :-)
Anthony Lewis
+1 for cron job rather than immediate deletion
Jeff L
+2  A: 

Since your PHP script is running on the server, the Excel file will have to be saved to the server to be read. Once you've read the file and stored it in the database, just delete it.

Anthony Lewis
A: 

I found the answer to my question here. It is a nice tutorial on uploading, moving, reading, and deleting files using PHP.

Thank you to all who contributed.

Clad
@Clad - you should tick the answer you found to be the most useful.
karim79