Jump to content

How to fetch data from a common text file?


Recommended Posts

hi,i'm using a file stored in a common folder which is shared among many scripts.I'm using the file() function to fetch the from the file and process that info.When the txt file is stored within the same folder/directory it is running cleanly ,but when the txt file is stored in a common position , the script shows the error the file not found error.I want to store the txt file in the common folder and i want the specific code to fetch the info .How can handle this situation,..The code isFile file.phpCode:

class hardcode{ 	var $textfile;	var $name;	var $no;	function setFile($fname) {			$this->textfile = $fname;	}	 function getDetails($text) {	  			 $this->name = $text;			 foreach(file($this->textfile) as $line)					// here even i tried foreach(file($this->textfile,1) as $line) for checking the file in include paths		   			 {				   $arr = explode('--', $line);					if(strcmp(trim($arr[1]),$this->name)==0) {							  $this->no = $arr[0];					}			 }			 if(isset($this->no)) { 				  return $this->no; 			 }	 } }

This file and the txt file which contains some info is stored in a common folder.check.phpCode:

<?php 		include "file.php";		 $fileobj->setFile('accounts.txt');		 $dbobj = new dbclass;		 $nn = $fileobj->getDetails('joseph'); ?>

File.php and accounts.txt is stored in a common folder and the check.php is stored in a separate folder.How can i handle this???

Link to post
Share on other sites


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

  • Create New...