CSV file into an array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stephen Preston

    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



  • Erwin Moller

    #2
    Re: CSV file into an array

    Stephen Preston wrote:
    [color=blue]
    > 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.[/color]

    Hi,
    [color=blue]
    >
    > 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?[/color]

    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:


    [color=blue]
    > 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.[/color]

    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>
    [color=blue]
    >
    > 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.
    >[/color]

    Then delete it afterwards.
    unlink()

    Regards,
    Erwin Moller

    Comment

    • Andy Jeffries

      #3
      Re: CSV file into an array

      On Thu, 09 Mar 2006 10:07:07 +0100, Erwin Moller wrote:[color=blue]
      > 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.[/color]

      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

      Comment

      • Stephen Preston

        #4
        Re: CSV file into an array

        Thanks

        The light has now come on :-)



        "Stephen Preston" <stephen_presto n@btconnect.com > wrote in message
        news:duoq8o$c74 $1@nwrdmz02.dmz .ncs.ea.ibs-infra.bt.com...[color=blue]
        > 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
        >
        >
        >[/color]


        Comment

        Working...