How to load a CSV/TXT file in a textarea?

Discussion in 'HTML' started by =?UTF-8?B?TWFydGluIFDDtnBwaW5n?=, Mar 25, 2006.

  1. Hello,

    I want to load a csv-file to a textarea field.

    Is it possible to do that only with HTML?
    Or do I need f.e.?

    If not... how can I do it?


    Regards,

    Martin
    =?UTF-8?B?TWFydGluIFDDtnBwaW5n?=, Mar 25, 2006
    #1
    1. Advertising

  2. =?UTF-8?B?TWFydGluIFDDtnBwaW5n?=

    Toby Inkster Guest

    Martin Pöpping wrote:

    > I want to load a csv-file to a textarea field.


    Easy way:

    <textarea name="foo"><?php
    $lines = ("mydata.csv");
    foreach ($lines as $l)
    printf("%s\n", htmlspecialchars($l));
    ?></textarea>

    > Is it possible to do that only with HTML?


    No: you'll either need a server-side script, like PHP, or to use AJAX
    techniques. Server-side is preferable as it will be vastly more reliable,
    but it does mean that your server needs to support that scripting language.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
    Toby Inkster, Mar 25, 2006
    #2
    1. Advertising

  3. =?UTF-8?B?TWFydGluIFDDtnBwaW5n?=

    Steve Pugh Guest

    Martin Pöpping <> wrote:

    >I want to load a csv-file to a textarea field.


    Textareas are for the input of text content, you would need to copy
    and paste the contents of the csv file into the textarea. To upload a
    csv file, or any other sort of file, there needs to be a <input
    type="file"> instead.

    If you're talking about displaying the contents of a csv file then
    forget all about form inputs and either simply link to the csv file:
    <a href="myfile.csv">Blah blah blah</a>,
    or parse the contents of the csv file on the server and include that
    in the ouput HTML,
    or load the csv file into an iframe and test to see whether browsers
    display it (as its plain text there's a good chance they will).

    >Is it possible to do that only with HTML?
    >Or do I need f.e.?


    What's f.e.?

    Steve
    --
    "My theories appal you, my heresies outrage you,
    I never answer letters and you don't like my tie." - The Doctor

    Steve Pugh <> <http://steve.pugh.net/>
    Steve Pugh, Mar 25, 2006
    #3
  4. Hi,

    Steve Pugh schrieb:
    > Martin Pöpping <> wrote:
    >
    >> I want to load a csv-file to a textarea field.

    >
    > Textareas are for the input of text content, you would need to copy
    > and paste the contents of the csv file into the textarea. To upload a
    > csv file, or any other sort of file, there needs to be a <input
    > type="file"> instead.


    Yes I know. I coded a normal HTML input type file which shows me the
    path of the file in a textbox.

    But now I want the content of my file in the textarea and I am asking
    myself, if this is possible only via HTML and without coding a file
    upload, for example with PHP

    >> Is it possible to do that only with HTML?
    >> Or do I need f.e.?

    >
    > What's f.e.?


    for example ;)


    Regards,

    Martin
    =?ISO-8859-1?Q?Martin_P=F6pping?=, Mar 25, 2006
    #4
  5. Martin Pöpping schrieb:
    > But now I want the content of my file in the textarea and I am asking
    > myself, if this is possible only via HTML and without coding a file
    > upload, for example with PHP


    If somebody is interested, here is a solution with PHP:

    <h1>Upload</h1>

    <form
    action="<?php echo $PHP_SELF ?>"
    method="post"
    enctype="multipart/form-data">
    <input type="file" name="probe" />
    <input type="submit" value="Go!" />
    </form>
    <hr />
    <?php
    if (isset($_FILES['probe']) and ! $_FILES['probe']['error']) {

    move_uploaded_file($_FILES['probe']['tmp_name'], "./tmp/newfile.txt");

    printf("Sie ist %u Bytes groß und vom Typ %s.<br />\n",
    $_FILES['probe']['size'], $_FILES['probe']['type']);

    ?>
    <textarea cols="50" rows="50"><?include('./tmp/newfile.txt')?></textarea>
    <? }
    ?>




    But my question still exists:

    Is it possible to show the content of a txt-file in a textarea only with
    using HTML?


    Bye,
    Martin
    =?ISO-8859-1?Q?Martin_P=F6pping?=, Mar 25, 2006
    #5
  6. Toby Inkster schrieb:
    > Martin Pöpping wrote:
    >
    >> I want to load a csv-file to a textarea field.

    >
    > Easy way:
    >
    > <textarea name="foo"><?php
    > $lines = ("mydata.csv");
    > foreach ($lines as $l)
    > printf("%s\n", htmlspecialchars($l));
    > ?></textarea>


    Why can´t i use:

    <textarea name="foo"><?php include('mydata.csv') ?></textarea>

    ?

    >> Is it possible to do that only with HTML?

    >
    > No: you'll either need a server-side script, like PHP, or to use AJAX
    > techniques. Server-side is preferable as it will be vastly more reliable,
    > but it does mean that your server needs to support that scripting language.


    Thanks,

    Martin
    =?UTF-8?B?TWFydGluIFDDtnBwaW5n?=, Mar 25, 2006
    #6
  7. On Sat, 25 Mar 2006, Martin Pöpping wrote:

    > <?
    > <textarea cols="50" rows="50"><?include('./tmp/newfile.txt')?></textarea>
    > <? }


    And when the file in question contains HTML markups?

    And when the character encoding of the uploaded file is not the same
    as the HTML page in which you want to embed it?
    Alan J. Flavell, Mar 25, 2006
    #7
  8. =?UTF-8?B?TWFydGluIFDDtnBwaW5n?=

    Toby Inkster Guest

    Martin Pöpping wrote:

    > Why can´t i use:
    >
    > <textarea name="foo"><?php include('mydata.csv') ?></textarea>


    What if mydata.csv contains "</textarea>"?

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
    Toby Inkster, Mar 25, 2006
    #8
  9. Toby Inkster schrieb:

    >> Why can´t i use:
    >>
    >> <textarea name="foo"><?php include('mydata.csv') ?></textarea>

    >
    > What if mydata.csv contains "</textarea>"?


    Ok, I got it :)
    =?UTF-8?B?TWFydGluIFDDtnBwaW5n?=, Mar 25, 2006
    #9
  10. Toby Inkster schrieb:

    > $lines = ("mydata.csv");

    are you sure that this works?

    > foreach ($lines as $l)
    > printf("%s\n", htmlspecialchars($l));

    I´m always getting a "Invalid argument supplied for foreach()".

    The file "mydata.csv" exists
    =?UTF-8?B?TWFydGluIFDDtnBwaW5n?=, Mar 25, 2006
    #10
  11. Martin Pöpping schrieb:
    > Toby Inkster schrieb:


    >> $lines = ("mydata.csv");

    > are you sure that this works?


    Ok. I found it.
    It´s: $lines = file("mydata.csv");
    =?UTF-8?B?TWFydGluIFDDtnBwaW5n?=, Mar 25, 2006
    #11
  12. =?UTF-8?B?TWFydGluIFDDtnBwaW5n?=

    Toby Inkster Guest

    Martin Pöpping wrote:

    > $lines = file("mydata.csv");


    That's the one. I missed out four rather vital characters!

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
    Toby Inkster, Mar 25, 2006
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. msn
    Replies:
    0
    Views:
    357
  2. MUK
    Replies:
    2
    Views:
    1,068
    Roedy Green
    Oct 22, 2005
  3. gikuh
    Replies:
    1
    Views:
    385
    Steve Pugh
    Jul 10, 2003
  4. Tintin92
    Replies:
    1
    Views:
    1,703
    Andrew Thompson
    Feb 14, 2007
  5. Sameen
    Replies:
    2
    Views:
    441
    Victor Bazarov
    Aug 29, 2005
Loading...

Share This Page