Hmm its not working
Posted: Thu Oct 06, 2005 9:53 pm
Heres what im trying to do:
Theres a file within the same folder as thisFile.php
named compName.tim that basicly is just a text file that says "test". I want to use this file to open that file and read whats in it and then display it.
normaly this would not be a difficult task however I need it to work in multiple folders. The way i have it set up, a user can create a new folder ( with a random name) and then it will copy the files (this one included) into it. I need to be able to read the contents of the file no matter what the folder name is.
This is what I have done so far however I'm very open to suggestions of different methods of accomplishing the same task. does anyone have any suggestions?
Theres a file within the same folder as thisFile.php
named compName.tim that basicly is just a text file that says "test". I want to use this file to open that file and read whats in it and then display it.
normaly this would not be a difficult task however I need it to work in multiple folders. The way i have it set up, a user can create a new folder ( with a random name) and then it will copy the files (this one included) into it. I need to be able to read the contents of the file no matter what the folder name is.
This is what I have done so far however I'm very open to suggestions of different methods of accomplishing the same task. does anyone have any suggestions?
Code: Select all
//thisFile.php
//*****************************************
//Function: getFileContents( $file )
//Parameter: accepts a variable containing the address
// of the file you want to get the contents of
//Returns the contents of the file
//*****************************************
function getFileContents( $file )
{
$fp = fopen($file, "r") or die("couldn't open $file"); while (!feof($fp))
{
$contents = fgets($fp, 1024);
}
fclose($fp);
settype($contents, string);
return $contents;
}
//end getFileContents() function
$var4 = "compName.tim";
$coName = getFileContents($var4);
echo "<HR><P>$coName<P><HR>";
?>