Jump to content

How to get content of a file in php


pnutUUM

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?
Link to comment
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?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.