Jump to content


Photo

How to get content of a file in php


  • Please log in to reply
1 reply to this topic

#1 pnutUUM

pnutUUM
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 02 March 2006 - 08:00 AM

hello,

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

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):
<?php
$filename = "/usr/local/something.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
?>

Or the easy, new PHP way:
<?php
$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