473,608 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
+ 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 3548
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($yourRe sultArray); ?>
</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
5627
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 results in a file, which doesn't hold the information of the changed array anymore. I dont know why. Here is the code: /*
6
10054
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) clump_class = calloc (ncolumns, sizeof(short *));
9
4315
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"); for(i=0;i<50;i++){
2
6848
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 replace just one item. I know I can get the entire array, then save the whole thing (with a for loop and if statements so that the changed data will be saved), but it seems like a lot of unnecessary reading and writing. Is there a way to directly save...
2
15986
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 script. Now I want to delete a line from a file. Line being the strings I got/saved to/from array of arrays.
29
10400
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 then print out the contents of the 2d array to the screen. I wil also need to append data to the .dat file but mostly right now I'm worrying about getting the info into the 2d array. My .dat file looks like this 1 20000 2 30000 3 40000
9
5200
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 facing problems: Assume that FILE* filePointer; unsigned char lineBuffer;
7
3583
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 and then output the contents of this array. The file seems to be parsed properly and the array gets populated but when I output the array the last line of my text file has filled the array. Text file and code as follows, Text File
19
5372
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 need to be able to accurately get the position in the file of that line. Since StreamReader and FileStream both buffer data, you can't equate the BaseStream.Position with the data you're reading from the stream. Lee Crabtree
13
10391
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 set of integers stored in an array.It would be a great help if you could provide some code for it.I tried the function fscanf but by that I am able to read only the first integer of the text file.Please help me.
0
8059
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8470
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8330
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6815
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6011
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5475
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3960
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4023
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2474
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 we have to send another system

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.