Re: I'm lost: text file upload
| From: | Nik Makepeace | Date: | Thu, 06 Mar 2003 07:28:10 +0000 |
| Subject: | Re: I'm lost: text file upload | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-138428@lists.php.net to get a copy of this message | ||
On Thu, 2003-03-06 at 15:33, John Taylor-Johnston wrote:
> I'm looking for a couple of lines of code so I can upload the contents of a *.txt into a
> buffer and declare it as a string so I can spit it back in a <textarea>. I don't want to
> necessarily upload a text file, only load it into a buffer.
>
> I'm lost
Will this do?
$fh=fopen($_FILES['userfile']['tmp_name'], 'r');
$fileContents=fread($fh, filesize($_FILES['userfile']['tmp_name']));
fclose($fh);
Assuming your form looked like this:
<form enctype="multipart/form-data" action="uploadintostring.php"
method="post">
<div>Read this file: <input name="userfile" type="file"></div>
<div><input type="submit" value="Read File"></div>
</form>
You can view this in action at
http://nikmakepeace.com/goodies/upload-string.php
Nik