I need to be able to read the content of a text file and display this content into a text area.
Now, I have a script working that allows a user to upload a .txt file onto the server and I successfully read this content and redisplay it.
I was wondering if it is possible to do the same without uploading the file to the server.
1/User load his file using a browse button
2/Script read the file content and redisplay it on the page?
Sorry if it has been previously covered , but I am stuck.
s
text file
Moderator: General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Sure is....
Instead of reading the file contents from a directory you give it, you read the file from:
$_FILES['form_field_name']['tmp_name']
instead (That's it's temporary location (and it will/should be removed when the sript is done with it)).
So
Instead of reading the file contents from a directory you give it, you read the file from:
$_FILES['form_field_name']['tmp_name']
instead (That's it's temporary location (and it will/should be removed when the sript is done with it)).
So
Code: Select all
$contents = file_get_contents($_FILES['form_field_name']['tmp_name']);
echo nl2br($contents);- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Microsoft do have some support for working with text files in JS but it's non standard and I'm not sure how well it actually works. Just allow it be uploaded but don't save it... like I showed.Wayne wrote:if you are talking about reading the text from the file without uploading the file to the server at all, then you will need to use a scripting language like javascript. This needs to be moved to the client side forum!
Thanks D11.d11wtq wrote:Sure is....
Instead of reading the file contents from a directory you give it, you read the file from:
$_FILES['form_field_name']['tmp_name']
instead (That's it's temporary location (and it will/should be removed when the sript is done with it)).
So
Code: Select all
$contents = file_get_contents($_FILES['form_field_name']['tmp_name']); echo nl2br($contents);
I should have thought of something like.
Now I get a open_basedir restriction in effect error, as the temp file is uploaded in C:\PHP\uploadtemp\ and my files are in a different folder.
s
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
These are my favourite questions.... regexp...snicolas wrote:Ok managed to read the file properly now.
I have a new question.
I upload a text file containing a list of email address.
How can i check that each email address is in a correct format?
s
The preg_...() functions will help but if you post an exmaple of the text file I'll give you some pointers
- n00b Saibot
- DevNet Resident
- Posts: 1452
- Joined: Fri Dec 24, 2004 2:59 am
- Location: Lucknow, UP, India
- Contact: