Three techniques commonly used in PHP programming

Source: Internet
Author: User
Tags php file php programming

1. Configure PHP file directory

As a scripting language for server-side interpretation execution, PHP programs are placed in a directory accessible to a server, and can generally be configured by modifying Apache Httpd.conj, such as our sentence in this document:

alias/test/"d:brhpwebsitebrhp/" then in the browser-side input: "Http://localhost/test/+PHP file name" can access the d:brhpwebsitebrhp/under the php file ; Visible the line is simply an alias for the directory where the php file is stored.

Second, you can also specify the DocumentRoot path to store the directory of server files, in Httpd.conj find the following two lines, where the path can be arbitrarily specified, your PHP files can also be placed in the directory, the server can also run them, such as "http:// localhost/+php file name ".

In general, the PHP file in the same place is better, you can easily manage, and other files in another place.

DocumentRoot "c:/usr/bin/html/"

2. Index files for server-side directories

In Httpd.conj, there is one line: DirectoryIndex index.html

The row specifies that the directory defaults to open file as index.html, and when a directory is accessed, the server automatically finds index.html and, if not, displays a list of all the files in the directory, and the default open file can be changed to something else. such as index.php3 and so on, but perhaps we have a lot of directories, whether it is to store pictures, text, and other information, or to store PHP files or other files directory, we do not want users to see the directory in the list of files, in the Httpd.conj A. htacess file is specified in the file, which produces a directory index file, for example, we use WordPad to create a. htacess file:

#. Htacess #

DirectoryIndex error_open.php

Create an error warning file again:

# error_open.php #

The error_open.php is a permission error warning file that places the 2 files under all protected directories and automatically turns to execute error_open.php when the user attempts to open the directory, displaying an error warning.
 
3. Directory Deletion clever implementation

As we know, there is a rename () function in PHP4 for/win32 that supports renaming directories/files, such as: Rename (OldPath, NewPath)//OldPath The original path to the file or directory;//NewPath for the new defined path;

Realize the OldPath renamed to NewPath.

There is no function to delete the directory/file in the PHP4, how to delete it? As we know, there is a row in the php.ini that is used to complete the HTTP upload operation of the temporary file directory configuration line: upload_tmp_dir=;

PHP4 support the configuration of the temporary directory (PHP3 not supported), when the upload operation is completed, automatically empty the temporary directory, OK, with it we can skillfully implement file/directory deletion, such as setting: Upload_tmp_dir= "d:brhpwebsitebrhp/tmp/"; To delete a directory path, perform: tmp= "d:brhpwebsitebrhp/tmp/" rename (path, TMP)?>;

After the file or directory path is renamed TMP, all files/directories under the TMP directory are automatically cleared and the deletion is completed.



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.