CSV file into an array

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

Threaded View

Can anyone explain in layman's terms the sequence of events required to  
upload a csv.txt and put the contents into an array.

Lets assume I have a form to select the csv.txt file, which then uploads,  
then what happens to it? where does it go? how do I get it out of the ether?
How, where do I access it.  Looking at the PHP manual, I deduce that I need  
to some how use the fopen and fgetcsv but unfortunately it reads like  
gobbledygook to me at the moment.

I can do, see and understand that if it was a picture, it goes into a  
directory on the server and resides there, but I don't want the csv.txt file  
to be saved.



Re: CSV file into an array

Stephen Preston wrote:

Quoted text here. Click to load it


It goes a a temp directory under a temp name.
You can easily retrieve it and store it in a place you want it to be.
This is done by the code in the receiving script (= the script mentioned in  
the action-tag of the form that contains the file-selector for the  

Read more here:

Quoted text here. Click to load it

First get the upload up and running, then start with the handling of the  
fgetcvs() is a nice helperfunction, but you can do it by hand too.
Really, just try it.  
No use in us telling you what to do to the letter if you don't understand it  

If you want to test your result somehow (the array), a handy function is  
print_r(). It prints the, possibly complex, structure of the array.
Use pre, like this:
 <? print_r($yourResultArray); ?>

Quoted text here. Click to load it

Then delete it afterwards.

Erwin Moller

Re: CSV file into an array

On Thu, 09 Mar 2006 10:07:07 +0100, Erwin Moller wrote:
Quoted text here. Click to load it

But if you try to handle it yourself don't fall in to the pitfall of just
exploding the string on "," as some CSV files may have commas within
columns, e.g.:

John Smith,21
"Doe, Jane", 21



Andy Jeffries MBCS CITP ZCE   | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

Re: CSV file into an array


The light has now come on :-)

Quoted text here. Click to load it

Site Timeline