PHP after a long period of development, a lot of users are very familiar with PHP, here I publish a personal understanding, and discuss with you. PHP is a server-side scripting language for creating dynamic Web pages. Like ASP and ColdFusion, users can mix PHP and HTML to write Web pages, and when a visitor browses to the page, the server first processes the PHP commands in the page and then sends the processed results along with the HTML content to the browser on the access side.
However, unlike ASP or ColdFusion, PHP is a source code open program with good cross-platform compatibility. Users can run PHP on the Windows NT system and on many versions of UNIX systems, and can run PHP as a built-in module or CGI program for the Apache server. In addition to being able to precisely control the display of Web pages, users can also send HTTP headers by using PHP. Users can set up cookies through PHP, manage user identification, and redirect users ' browsing pages. PHP has a very powerful database support capability to access almost all of the more popular database systems available today. In addition, PHP can be integrated with multiple external libraries, providing users with more useful functions, such as generating PDF files.
The user can enter the PHP command code directly in the Web page, so no special development environment is required. In the Web page, all of the PHP code is placed in the. In addition, users can choose to use forms such as the. The PHP engine automatically recognizes and processes all the code in the page between the PHP delimiters.
The syntax structure of the PHP scripting language is very similar to the grammar style of the C and Perl languages. The variable does not need to be declared before the user can use the variable. The process of creating an array using PHP is also very simple. PHP also has the basic object-oriented component function, which can greatly facilitate the user to effectively organize and encapsulate the code they write. Here to introduce you about the PHP upload problem.
Example 1. Make file PHP upload effective
Please refer to Functions Is_uploaded_file () and Move_uploaded_file () for further information. The following example processes file uploads that are provided by the form.
- PHP
- In PHP versions earlier than 4.1.0, $HTTP _post_files should be used instead
- of $_files.
- $ Uploaddir = '/var/www/uploads/' ;
- $ UploadFile = $uploaddir. BaseName ($_files[' userfile ' [' name ']);
- Echo ' < Pre > ';
- if (Move_uploaded_file ($_files[' userfile ' [' tmp_name '], $uploadfile)) {
- echo "File is valid, and was successfully UPLOADED.N";
- } else {
- echo "Possible file upload attack!n";
- }
- Echo ' Here's some more debugging info: ';
- Print_r ($_files);
- print " pre>";
- ?>
A script that accepts PHP uploads files should implement any logically necessary checks in order to decide what to do with the file next. For example, you can use the $_files[' userfile ' [' size '] variable to exclude files that are too large or too small, or you can exclude file types and files that do not conform to a standard by $_files[' userfile ' [' type '] variables, But just consider this as the first step in a series of checks, because this value is completely controlled by the client and is not checked on the PHP side. From PHP 4.2.0, you can also plan what to do next with different error codes by $_files[the ' userfile ' [' ERROR '] variable. In any case, either remove the file from the temp directory or move it to a different location.
If no uploaded file is selected in the form, the value of PHP variable $_files[' userfile ' [' size '] will be null for 0,$_files[' userfile ' [' tmp_name ']. If the file has not been moved elsewhere and has not been renamed, the file will be deleted at the end of the form request.
http://www.bkjia.com/PHPjc/446565.html www.bkjia.com true http://www.bkjia.com/PHPjc/446565.html techarticle PHP After a long period of development, a lot of users are very familiar with PHP, here I publish a personal understanding, and discuss with you. PHP is a server-side scripting language for creating Dynamic Web pages ...