Facebook
From Queen Human, 7 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 318
  1. <?php
  2.  
  3.         class fileModule
  4.         {
  5.                 protected $_handle;
  6.                
  7.                         public function __construct($sth)
  8.                         {
  9.                                 $this->_handle = $sth;
  10.                         }
  11.                        
  12.                         public function openFile($role)
  13.                         {
  14.                                 $this->_handle = fopen($this->_handle, $role);
  15.                         }
  16.                        
  17.                         public function addContent($content)
  18.                         {
  19.                                 fwrite($this->_handle, $content);
  20.                         }
  21.                        
  22.                         public function getContent()
  23.                         {
  24.                                 $content = fread($this->_handle, filesize($this->_handle));
  25.                                 echo $content;
  26.                         }
  27.                        
  28.                         public function __destruct()
  29.                         {
  30.                                 fclose($this->_handle);
  31.                         }
  32.                
  33.         }
  34.  
  35.  
  36.        
  37.  
  38. ?>
  39.  
  40.  
  41. <?php
  42.  
  43.         require_once 'modules/filecontroller.class.php';
  44.  
  45.         $stmt = new fileModule('test.txt');
  46.         $stmt->openFile('a');
  47.         $stmt->addContent('Hello kitty!');
  48.         $stmt->getContent();
  49.        
  50.         echo 'File has been created!';
  51.        
  52. ?>