PHP: Arbitrary file format with HTML display

Source: Internet
Author: User
Saving an HTML file to a file (such as test.aaa) with a suffix of AAA (or any other format), and then opening it in a browser, finds that the browser cannot be displayed as a Web page, but instead displays the HTML source in the TEST.AAA.
And if it is saved as: test.html, it is normal in the webpage.
For example: in the root directory of the Web site, there are 2 files: test.html and TEST.AAA
The code is as follows:


  
   

Access results:
http://127.0.0.1/test.aaa==> Display Web page source code
http://127.0.0.1/test.html==> Display a button
Question: How can a browser display a file in any format as a Web page?

Reply content:

Saving an HTML file to a file (such as test.aaa) with a suffix of AAA (or any other format), and then opening it in a browser, finds that the browser cannot be displayed as a Web page, but instead displays the HTML source in the TEST.AAA.
And if it is saved as: test.html, it is normal in the webpage.
For example: in the root directory of the Web site, there are 2 files: test.html and TEST.AAA
The code is as follows:


  
   

Access results:
http://127.0.0.1/test.aaa==> Display Web page source code
http://127.0.0.1/test.html==> Display a button
Question: How can a browser display a file in any format as a Web page?

Set HTTP header to Content-Type: text/html .

In addition, this should be related to your Web service area and it has nothing to do with PHP, for example, if you use Nginx, you have to .aaa change the suffix of the filename corresponding to the MIME Type text/html .

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