What you're looking for, on the client side, is <input type="file" name="myfile">
which allows the user to browse for a file - of any type - and upload it to the server. After it's uploaded, you get access to it from PHP through the $_FILES
structure. See more here.
Selecting text file then reading its contents in PHP
-
16-07-2023 - |
Question
I was having a problem with pasting huge amount of text in a text area in HTML as it causes delays and slow processing time. Then one of the responders here in Stackoverflow suggested I upload the text file instead.
Now I am having problems on just how to do that exactly. I've been researching for hours but couldn't find the answer I'm looking for. What I need is for the user to select the text file then PHP reads the contents of that file into a variable. The file contains server logs so it should be huge.
I've been researching and options like fopen() or file_get_contents() seem to only open specific files, I need it dynamic, the user must select the file himself. Also, I am confused if I want to upload the file into the server or just read it's contents without uploading. I maybe prefer just reading.
We run a team that checks the user log of any users having issues, we have a tool that downloads a text file of any selected user, we then need to read that log into our PHP website/tool.
Solution
OTHER TIPS
You may try this
file_get_contents($_FILES['uploadedfile']['tmp_name']);
Store this result into one variable. Print this result. Check what will be shown.
But the condition is you should use html form. I think you know this basic concepts.