Jump to content

Archived

This topic is now archived and is closed to further replies.

pnutUUM

How to get content of a file in php

Recommended Posts

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?

Share this post


Link to post
Share on other sites
There are 2 main methods:

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

Or the easy, new PHP way:
[code]<?php
$filename = "/usr/local/something.txt";
$contents = file_get_contents($filename);
?>[/code]

is that what you were after?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.