\\n\\n\";\r\n echo \"

File Open Example

\";\r\n \r\n class FileOpenSaver{\r\n private $filePath;\r\n private $file;\r\n private $fileMode;\r\n //class constructor\r\n public function __construct($fPath, $mode){\r\n $this->filePath=$fPath;\r\n $this->fileMode=$mode;\r\n }\r\n //class destructor\r\n public function __destruct(){\r\n if(! $this->file==null){\r\n echo \"Closing File!
\";\r\n fclose($this->file);\r\n echo \"File Closed!\";\r\n }\r\n }\r\n //try to open a file\r\n public function openFile(){\r\n try {\r\n $this->file = fopen($this->filePath, $this->fileMode);\r\n }catch (Exception $e){\r\n echo \"Captured Exception: \", $e->getMessage(), \"
\";\r\n }\r\n }\r\n //try to write something in a file\r\n public function writeFile($text){\r\n try {\r\n fwrite($this->file,$text);\r\n }catch (Exception $e){\r\n echo \"Captured Exception: \", $e->getMessage(), \"
\";\r\n }\r\n }\r\n //try to read a file and show in the page\r\n public function readaFile(){\r\n try {\r\n while(!feof($this->file)){\r\n echo fgets($this->file).\"
\";/","answerCount":1,"upvoteCount":0,"suggestedAnswer":[{"@type":"Answer","text":"$Text = fgets($this->file); \necho $Text; \n\nThis should work. ","upvoteCount":0}]} }
0

fopen trouble

I created a class in php to open a file read and write, the write function is working just fine, the problem is to read, i don't have any errors and still don't work, below i've pasted my code, thanks for the help! echo "<!DOCTYPE html> \n<html>\n<head><title>file open</title>\n<link href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' rel='stylesheet' integrity='sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u' crossorigin='anonymous'>\n<script src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js' integrity='sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa' crossorigin='anonymous'></script>\n</head>\n<body>"; echo "<div class='container'><h1>File Open Example</h1>"; class FileOpenSaver{ private $filePath; private $file; private $fileMode; //class constructor public function __construct($fPath, $mode){ $this->filePath=$fPath; $this->fileMode=$mode; } //class destructor public function __destruct(){ if(! $this->file==null){ echo "Closing File!<br>"; fclose($this->file); echo "File Closed!"; } } //try to open a file public function openFile(){ try { $this->file = fopen($this->filePath, $this->fileMode); }catch (Exception $e){ echo "Captured Exception: ", $e->getMessage(), "<br>"; } } //try to write something in a file public function writeFile($text){ try { fwrite($this->file,$text); }catch (Exception $e){ echo "Captured Exception: ", $e->getMessage(), "<br>"; } } //try to read a file and show in the page public function readaFile(){ try { while(!feof($this->file)){ echo fgets($this->file)."<br>";/

16th Dec 2016, 6:08 PM
Nilton Tadeu Ferreira Filho
Nilton Tadeu Ferreira Filho - avatar
1 Answer
0
$Text = fgets($this->file); echo $Text; This should work.
27th Dec 2016, 9:39 AM
posajpous