473,480 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 3541
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
5618
by: Jens Mittag | last post by:
Hi! In my code, I have an array of a structure, which I want to save to a binary file. When the array is just created, everything works fine, but when I change contents of the array, saving...
6
10034
by: Betty Hickman | last post by:
I'm having trouble writing a 2D array to a binary file. Here's what I have: FILE *outfile; short **clump_class; clump_class = malloc(nrows * sizeof(short *)); for (i=0; i<nrows; ++i)...
9
4304
by: steph_de_marseille | last post by:
I would like to write a x array in a file. If the array has a small numbers of columns I know I can use a loop like: int i,j; double array; FILE *file1; file1=fopen("data.dat","w");...
2
6836
by: melanieab | last post by:
Hi, I'm trying to store all of my data into one file (there're about 140 things to keep track of). I have no problem reading a specific string from the array file, but I wasn't sure how to...
2
15965
by: kelly | last post by:
Hi, I don't have a code to show you, what I need are references or algorithms so that I'm in a right track. By the way, thanks for introducing me the array or arrays. Now I can continue my...
29
10370
by: yourmycaffiene | last post by:
Okay, this if my first post so go easy on me plus I've only been using C for a couple of weeks. I'm working on a program currently that requires me to read data from a .dat file into a 2d array and...
9
5186
by: Adi | last post by:
Hello eveyone, I wanna ask a very simple question here (as it was quite disturbing me for a long time.) My problem is to read a file line by line. I've tried following implementations but still...
7
3567
by: theballz | last post by:
Hi, I am learning c programming and come across a problem i cant seem to solve. I have a file which i wish to parse and put certain lines (which do not contain a hash character) into an array...
19
5349
by: Lee Crabtree | last post by:
Is there a class in the framework that allows me read text from a file in an unbuffered manner? That is, I'd like to be able to read lines in the same manner as StreamReader.ReadLine(), but I also...
13
10369
by: rohit | last post by:
Hi All, I am new to C language.I want to read integers from a text file and want to do some operation in the main program.To be more specific I need to multiply each of these integers with another...
0
7055
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7059
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7103
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6758
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7010
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3011
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
572
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.