PHP generates static files

Source: Internet
Author: User

This article is quoted from network

First introduce your own file class:

* File Processing class
Class Files
Private $resource = null; File resource handle
function __construct ($fileName, $mode = ' R ')
$dirName = DirName ($fileName);//file path
$baseName = BaseName ($fileName);//File name

Check and create a folder
Self::mkdir ($dirName);

$this->resource = fopen ($fileName, $mode. ' B ');
if ($this->resource)
Flock ($this->resource,lock_ex);//Lock-in
File Write function
Public function write ($content)
$worldsnum = fwrite ($this->resource, $content);
Return Is_bool ($worldsnum)? False: $worldsnum;

Write a function to generate a static file:

Private Function writehtml ($path, $content) {
if (! class_exists (' Files ')) {
$this-Load->file (APPPATH. ' Libraries/files '. EXT);//I use the CI framework, introduce the file class here to make a slight change
$f = new Files ($path, ' w+ ');
$res = $f->write ($content);
$f->save ();

Finally call the above function where you need to generate a static page:

function crativehtml{
$url = "php dynamic file path";
$content = file_get_contents ($url);//Get File contents
$this-_writefile ($path. ' File name. html ', $content);

Just such a static file is generated, the last file can be written in multiple places to generate different static files,

PHP generates static files

Related Article

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: 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.