468,256 Members | 1,423 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,256 developers. It's quick & easy.

CSV file into an array

Hi

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.

--
Regards

Stephen

Mar 9 '06 #1
3 3434
Stephen Preston wrote:
Hi

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

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?
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
fileupload.)

Read more here:
http://nl2.php.net/manual/en/features.file-upload.php

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.
First get the upload up and running, then start with the handling of the
file.
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
yourself.

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:
<pre>
<? print_r($yourResultArray); ?>
</pre>

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.


Then delete it afterwards.
unlink()

Regards,
Erwin Moller
Mar 9 '06 #2
On Thu, 09 Mar 2006 10:07:07 +0100, Erwin Moller wrote:
First get the upload up and running, then start with the handling of the
file.
fgetcvs() is a nice helperfunction, but you can do it by hand too. Really,
just try 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.:

Name,Age
John Smith,21
"Doe, Jane", 21

Cheers,
Andy

--
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

Mar 9 '06 #3
Thanks

The light has now come on :-)

"Stephen Preston" <st*************@btconnect.com> wrote in message
news:du**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
Hi

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.

--
Regards

Stephen

Mar 9 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Betty Hickman | last post: by
9 posts views Thread by steph_de_marseille | last post: by
2 posts views Thread by melanieab | last post: by
2 posts views Thread by kelly | last post: by
29 posts views Thread by yourmycaffiene | last post: by
9 posts views Thread by Adi | last post: by
7 posts views Thread by theballz | last post: by
19 posts views Thread by Lee Crabtree | last post: by
13 posts views Thread by rohit | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.