1

I am making a file input that takes in a txt file. How do I access the contents of the file that just got uploaded using PHP?

1
  • 1
    In the future you can search for functions from php.net, which is a very good reference. Commented Nov 13, 2010 at 2:33

2 Answers 2

2
$contents = file_get_contents('/path/to/file');
Sign up to request clarification or add additional context in comments.

2 Comments

@Lajos Arpad: I wonder if an answer can be longer for such question ;-)
Unfortunately they can, that's why I upvoted your answer: It helped the person who asked the question and didn't contain not needed arguments. :)
2

If you want to access the file directly:

$content = file_get_contents($_FILES["file_input_field_name"]["tmp_name"]);

If you want to store the file, you'll want to check out:

http://php.net/move_uploaded_file

1 Comment

Also, make sure to use is_uploaded_file (us3.php.net/is_uploaded_file) before reading "uploaded" files & check error conditions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.