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

G

Guest

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
 
T

Toby Inkster

Martin said:
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));
?> said:
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.
 
S

Steve Pugh

Martin Pöpping said:
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
 
?

=?ISO-8859-1?Q?Martin_P=F6pping?=

Hi,

Steve said:
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
What's f.e.?

for example ;)


Regards,

Martin
 
?

=?ISO-8859-1?Q?Martin_P=F6pping?=

Martin said:
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
 
G

Guest

Toby said:
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>

?
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
 
A

Alan J. Flavell

<?
<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?
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top