Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Class Untuk Membuat File Text dan Membaca File Text
- // Masukkan kedalam file "system/GF_Text.php"
- class File_Generator
- {
- private $content_data;
- private $file_name;
- private $message_die = "Unable to open file !";
- private $length_file = false;
- public function setData($content)
- {
- if ($content)
- {
- $this->content_data = $content;
- }
- }
- public function setMessageDie($value = "")
- {
- $this->message_die = $value;
- }
- public function setFile($value = 'default.txt')
- {
- $this->file_name = $value;
- }
- public function create()
- {
- if (is_array($this->file_name))
- {
- for ($i=0; $i < count($this->file_name) ; $i++)
- {
- $fn = __STORAGE_DIR__.$this->file_name[$i] ;
- if (strpos($fn, '/') !== false)
- {
- if (! is_dir(dirname($fn,1)))
- {
- mkdir(dirname($fn,1), 0777, true);
- }
- }
- $file = fopen($fn, "w") or die($this->message_die." : ".$this->file_name);
- fwrite($file, $this->content_data);
- fclose($file);
- }
- }
- else
- {
- $file = fopen(__STORAGE_DIR__.$this->file_name, "w") or die($this->message_die);
- fwrite($file, $this->content_data);
- fclose($file);
- }
- }
- public function read()
- {
- if (file_exists(__STORAGE_DIR__.$this->file_name))
- {
- $file = fopen(__STORAGE_DIR__.$this->file_name, "r") or die($this->message_die." : ".$this->file_name);
- if ( ($this->length_file != false ) && is_numeric($this->length_file))
- {
- return fgets($file,$this->length_file);
- }
- else
- {
- return fgets($file);
- }
- fclose($file);
- }
- else
- {
- return false;
- }
- }
- public function setLength($value)
- {
- if (is_numeric($value))
- {
- $this->length_file = $value;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement