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

Discussion in 'HTML' started by Guest, Mar 25, 2006.

  1. Guest

    Guest Guest


    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?


    Guest, Mar 25, 2006
    1. Advertisements

  2. Guest

    Toby Inkster Guest

    Easy way:

    <textarea name="foo"><?php
    $lines = ("mydata.csv");
    foreach ($lines as $l)
    printf("%s\n", htmlspecialchars($l));
    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 Inkster, Mar 25, 2006
    1. Advertisements

  3. Guest

    Steve Pugh Guest

    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).
    What's f.e.?

    Steve Pugh, Mar 25, 2006
  4. Hi,

    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
    for example ;)


    =?ISO-8859-1?Q?Martin_P=F6pping?=, Mar 25, 2006
  5. If somebody is interested, here is a solution with PHP:


    action="<?php echo $PHP_SELF ?>"
    <input type="file" name="probe" />
    <input type="submit" value="Go!" />
    <hr />
    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?

    =?ISO-8859-1?Q?Martin_P=F6pping?=, Mar 25, 2006
  6. Guest

    Guest Guest

    Why can´t i use:

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


    Guest, Mar 25, 2006
  7. 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
  8. Guest

    Toby Inkster Guest

    What if mydata.csv contains "</textarea>"?
    Toby Inkster, Mar 25, 2006
  9. Guest

    Guest Guest

    Ok, I got it :)
    Guest, Mar 25, 2006
  10. Guest

    Guest Guest

    are you sure that this works?
    I´m always getting a "Invalid argument supplied for foreach()".

    The file "mydata.csv" exists
    Guest, Mar 25, 2006
  11. Guest

    Guest Guest

    Ok. I found it.
    It´s: $lines = file("mydata.csv");
    Guest, Mar 25, 2006
  12. Guest

    Toby Inkster Guest

    That's the one. I missed out four rather vital characters!
    Toby Inkster, Mar 25, 2006
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.