Creating directories and File writes

Source: Internet
Author: User

Create directories as well as file writes, as required by friends can refer to below.


Requirements Description:
Generates a static HTML page of the previewed PHP page and stores it in the appropriate folder.

1. The preview information is the query database to upload the corresponding information to the view layer display.

2. Generate HTML for the PHP page

    1. $root _dir = $_server["Document_root"]; Get root directory
    2. $NowYear = Date ("Y"); Create a directory with a "year" level
    3. $dir _path = "$root _dir/abc/bcd/". $NowYear. " /". $edm [' Showtime ']."; /Get a directory based on the current year and the corresponding time
    4. $file _path = $dir _path. " /index.html "; File name is index.html
    5. mkdir ($dir _path,0777,true);//Create a file directory 777 is a permission, true indicates that a multilevel directory can be generated
    6. $EDM _templates = $sqlquery _get_data;//sql Get data
    7. $data = Array (///page requires some data
    8. ' Info ' = $info,
    9. ' Result ' = $edm _templates,
    10. );
    11. $this->load->vars (' info ', $data);
    12. $data = $this->load->view (URL, ", true); Get the data needed to generate HTML
    13. if (empty ($data)) Ajaxreturn ("," no Read permission or no query to the corresponding file!) ', 0);
    14. File_put_contents ($file _path, $data);//Generate file
    15. Ajaxreturn (', ' Build succeeded! ', 2);
Copy Code

The previous idea was that the file_get_contents () function was to get the page information, but the page needed to be logged in. That is, the server requests the page, and then it is blocked on the landing page. The previous use of this function is then generated by the login page.

In general, the creation of a directory is the MkDir function, the file is written with file_put_contents This function is more convenient.

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