Jump to content

Import .txt directly to <textarea>


soma56

Recommended Posts

I hope someone can help me out with this. What I would like to do is import a text file dircetly to a text area. I can't seem to find any examples on this (Yes I did search Google). I know how to upload but I'm not interested in storing files on the server - but rather just importing them directly to a textarea.

 

Can anyone point me in the right direction?

 

I can upload:

<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

 

I can read:

$myFile = "testFile.txt";
$fh = fopen($myFile, 'w')

 

But I'm not interested in either of these as they are unnecessary steps (or are they?). Is there not a way to simply browse/import a text file directly to a textarea  (or anywhere for that matter) without having to actually save the file to the server?

 

Something like this:

<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

 

//uploader.php

if (isset($_POST['submit'])) {

        $content = $_POST['"grab the contents of the file"'];
        echo "<textarea>";
        echo $content;
        echo "</textarea>";
}

 

 

 

Link to comment
Share on other sites

Can't just do an include?

 

<form enctype="multipart/form-data" action="" method="POST">
Upload: <input name="file" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
<?
$my_file = $_FILES["file"]["tmp_name"];
if (file_exists($my_file)) {
include($my_file);
} else {
echo "No file to display";
}
?>

Link to comment
Share on other sites

This would work better because can do returns for each line.

 

<form enctype="multipart/form-data" action="" method="POST">
Upload: <input name="file" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
<?
$my_file = $_FILES["file"]["tmp_name"];
if (file_exists($my_file)) {
$data = file($my_file);
$total = count($data);
echo "<br />Total lines: $total<br />";
foreach ($data as $line) {
echo "$line<br />";
}
} else {
echo "No file to display";
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.