NFePHP\Common\Files\FilesFolders::saveFile PHP Method

saveFile() public static method

saveFile
public static saveFile ( string $path = '', string $filename = '', string $content = '' ) : boolean
$path string
$filename string
$content string
return boolean
    public static function saveFile($path = '', $filename = '', $content = '')
    {
        self::createFolder($path);
        $filePath = $path . DIRECTORY_SEPARATOR . $filename;
        if (!file_put_contents($filePath, $content)) {
            return false;
        }
        if (!chmod($filePath, 0777)) {
            return false;
        }
        return true;
    }

Usage Example

示例#1
0
 /**
  * verifica
  * Verifica o status da SEFAZ com o webservice e retorna tags html com o resultado
  * @param string $config json do arquivo de configuração
  * @return string
  */
 public static function verifica($config = '')
 {
     $aRetorno = array();
     if (empty($config)) {
         return '';
     }
     self::$config = $config;
     if (is_file(APP_ROOT . '/base/status.json')) {
         $aRetorno = (array) json_decode(FilesFolders::readFile(APP_ROOT . '/base/status.json'));
     }
     $tstmp = DateTime::convertSefazTimeToTimestamp($aRetorno['dhRecbto']);
     $tsnow = time();
     $dif = $tsnow - $tstmp;
     //caso tenha passado mais de uma hora desde a ultima verificação
     if ($dif > 3600) {
         self::$nfe = new ToolsNFe($config);
         self::$certTS = self::$nfe->certExpireTimestamp;
         self::$nfe->sefazStatus('', '', $aRetorno);
         $retJson = json_encode($aRetorno);
         FilesFolders::saveFile(APP_ROOT . '/base', 'status.json', $retJson);
     }
     $tstmp = DateTime::convertSefazTimeToTimestamp($aRetorno['dhRecbto']);
     $dhora = date('d/m/Y H:i:s', $tstmp);
     $htmlStatus = "<p class=\"smallred\">OFF-LINE</p>\n<p class=\"smallred\">{$dhora}</p>";
     if ($aRetorno['cStat'] == '107') {
         $htmlStatus = "<p class=\"smallgreen\">SEFAZ On-Line</p>\n<p class=\"smallgreen\">{$dhora}</p>";
     }
     return $htmlStatus;
 }
All Usage Examples Of NFePHP\Common\Files\FilesFolders::saveFile