Php static file generation class. Php Tutorial static file generation class defined (php Tutorial ox) ordie (header (http1.1403notforbidden); classinclude_createstatic {private $ htmlpath; private $ path; public $
Php Tutorial static file generation class
Defined ('php tutorial X') or die (header ("http/1.1 403 not forbidden "));
Class include_createstatic
{
Private $ htmlpath = '';
Private $ path = '';
Public $ monthpath = '';
Private $ listpath = '';
Private $ content = '';
Private $ filename = '';
Private $ extname = '.html ';
Public function createhtml ($ type, $ desname, $ content)
{
$ This-> htmlpath = getappinf ('htmlpath ');
If (! File_exists ($ this-> htmlpath ))
{
@ Mkdir ($ this-> htmlpath );
}
$ This-> path = $ this-> htmlpath. $ this-> monthpath .'/';
If (! File_exists ($ this-> path ))
{
@ Mkdir ($ this-> path );
}
$ This-> listpath = $ this-> htmlpath. 'list /';
If (! File_exists ($ this-> listpath ))
{
@ Mkdir ($ this-> listpath );
}
Switch ($ type)
{
Case 'index ':
$ This-> filename = $ desname;
Break;
Case 'List ':
$ This-> filename = $ this-> listpath. $ desname;
Break;
Case 'View ':
$ This-> filename = $ this-> path. $ desname;
Break;
}
$ This-> filename. = $ this-> extname;
$ This-> content = $ content;
}
Public function write ()
{
$ Fp = fopen ($ this-> filename, 'WB ');
If (! Is_writable ($ this-> filename ))
{
Return false;
}
If (! Fwrite ($ fp, $ this-> content ))
{
Return false;
}
Fclose ($ fp );
Return $ this-> filename;
}
}
// Method 2
If (file_exists ("./index.htm") // check whether the static index.htm file exists.
{
$ Time = time ();
// Is the file modification time different from the current time? Otherwise, the htm file will be generated again.
If (time-filemtime ("./index.htm") <600)
{
Header ("location: classhtml/main.htm ");
}
}
// Add ob_start () to your start ();
Ob_start ();
// The homepage content is your dynamic part
// Add ob_end_clean () to the end and output this page to a variable.
$ Temp = ob_get_contents ();
Ob_end_clean ();
// Write a file
$ Fp = fopen ("./index.htm", 'w ');
Fwrite (fp, temp) or die ('file writing error ');
// Echo "html generation complete! ";
Define static file generation class defined ('php tutorial X') or die (header (http/1.1 403 not forbidden); class include_createstatic {private $ htmlpath = ''; private $ path = ''; public $...