Import from csv file to MySQL

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I'm in the middle of writing a script to import a csv file into mySQL
(as apart of a bigger project)

I need to know what are the best steps to go from $_FILES to file().

Once the file is read into an array I should be right. I don't want to
keep a copy of the file uploaded either, as once it is imported I will
have no use for it.

I'm not sure, do I copy it store it then use it or is there a faster
way? Will the temp file be deleted or do I have to delete it?

Re: Import from csv file to MySQL

I am at work so I cant give you the code but what you need to do is the

1. upload to a temporary directory (say /temp - this folder will need
to have appropriate access rights)

2. use the file_read funcions (look for tutorials on flat files for all

3. import your data into the DB

4. If successful use unlink($file); to delete OR print error message


Smitro wrote:
Quoted text here. Click to load it

Re: Import from csv file to MySQL

I think I've worked it out, I'm in the middle of writing the script.

I upload the file into $_FILES

grab the temp directory and temp file name etc from $_FILES

then run the mysql_query () something along the lines of "LOAD DATA
INFILE '$file_location' INTO TABLE tale_name etc...

I guess it's one of these things, if you look hard enough you'll find
an answer.  

Thanks anyway.

Site Timeline