Jump to content


How to get content of a file in php

  • Please log in to reply
1 reply to this topic

#1 pnutUUM

  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 02 March 2006 - 08:00 AM


i just want to know how can i read content from a file to be used as the input to be saved in the database...
what i want to do is to read a text file containing student's matric number and their names. the user only have to browse the location of the file to register students. then the matric numbers and names will be added to the database....so,no need to register students one by one...can anybody help me?

#2 heckenschutze

  • Members
  • PipPipPip
  • Advanced Member
  • 257 posts
  • LocationAustralia

Posted 02 March 2006 - 09:03 AM

There are 2 main methods:

The C based way (example from php.net):
$filename = "/usr/local/something.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));

Or the easy, new PHP way:
$filename = "/usr/local/something.txt";
$contents = file_get_contents($filename);

is that what you were after?

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users