Php static file generation class _ PHP Tutorial

Source: Internet
Author: User
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 $...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.