<?php
class Gen_number {
private $path='generate';
private $lists_file=[];
private $n_zero=3;
private $current_item=0;
public $file_name='';
public $ext='.doc';
public function __construct($file_name='_file',$options=[]) {
$this->file_name=$file_name;
if(!empty($options)){
foreach ($options as $k=>$option)if(property_exists($this,$k))$this->$k=$option;
}
$this->init();
}
public function init(){
$file=scandir($this->path);
foreach ($file as $items){
if($items!='' && $items!='..')$this->lists_file[]=$items;
}
$this->create_name_file();
}
private function create_name_file(){
$this->current_item=count($this->lists_file);
if($this->current_item==0 || empty($this->current_item))$this->current_item=1;
$this->generate_zeros();
}
private function generate_zeros(){
$temp_file_name='';
$zeros=$this->n_zero-(strlen($this->current_item));
if($zeros<0)$zeros=1;
for($i=0;$i<$zeros;$i++)$temp_file_name.='0';
$this->file_name=$temp_file_name.$this->current_item.$this->file_name.$this->ext;
}
public function create_docs($string_output){
file_put_contents($this->path.'/'.$this->file_name,$string_output);
}
public function create_download_file(){
return file_get_contents($this->path.'/'.$this->file_name);
}
}