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?
2 Answers
$contents = file_get_contents('/path/to/file');
2 Comments
zerkms
@Lajos Arpad: I wonder if an answer can be longer for such question ;-)
Lajos Arpad
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. :)
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:
1 Comment
Eric Butera
Also, make sure to use is_uploaded_file (us3.php.net/is_uploaded_file) before reading "uploaded" files & check error conditions.