Introduction: This is a detailed page of PHP usage experience. It introduces the related knowledge, skills, experience, and some PHP source code.
Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 340724 'rolling = 'no'>
1. Apache configuration
I downloaded Apache 2.2 and PHP 5.2.17 (vc6 x86 thread safe)
Note: The non-thread safe version of vc6 x86 does not seem to work on our host.
First, decompress the downloaded PHP file to c: \ PHP, change the php. ini-Recommend file in the folder to PhP. ini, locate lines around 542, and find the followingCodeParameter: Extension = ". /", changed to extension =" C:/PHP/EXT/"and told the PHP extension library directory to" C:/PHP/EXT /". Save and copy PHP. ini to c: \ windows \ PHP. ini. To Upgrade PHP, you only need to overwrite the new version to c: \ PHP.
Next, find the Apache configuration file (in .. /CONF/httpd. conf), find the "loadmodule" section, append: loadmodule php5_module "C:/PHP/php5apache2_2.dll", find the "addtype" section, and append: addtype application/X-httpd-PHP. PHP. Restart the apache service.
Note: To modify the website directory, go to httpd. in Conf, find DocumentRoot "C:/program files/Apache Software Foundation/apache2.2/htdocs" to the desired directory. At the same time, <directory "C: /program files/Apache Software Foundation/apache2.2/htdocs "> also need to be modified. If you need to modify the home page, you can find "<ifmodule dir_module> directoryindex index. php </ifmodule>" and change it to index. php.
2. File Upload
First, define some parameters:
<? PHP // upload file type list
$ Uptypes = array (
'Image/jpg ',
'Image/JPEG ',
'Image/PNG ',
'Image/pjpeg ',
'Image/gif ',
'Image/BMP ',
'Image/X-PNG'
);
$ Max_file_size = 2000000; // size limit of uploaded files, in bytes
$ Destination_folder = "uploading/"; // File Upload path?>
Next, add the form:
<Form enctype = "multipart/form-Data" method = "Post" name = "upform">
Upload files:
<Input name = "upfile" type = "file">
<Input type = "Submit" value = "Upload"> <br>
The file type that can be uploaded is: <? PHP echo implode (',', $ uptypes);?>
</Form>
Then process the upload request:
<? PHP
If ($ _ server ['request _ method'] = 'post ')
{
$ File = $ _ FILES ['upfile'];
// $ File contains four elements: name, type, size, tmp_name. Each element is an array.
// Whether a file exists
If (! Is_uploaded_file ($ file ['tmp _ name'])
{
Echo "<font color = Red> File Upload Failed! </Font> ";
Exit ();
}
// Check the file size
If ($ max_file_size <$ file ['SIZE'])
{
Echo "<font color = Red> the size of the uploaded file exceeds". ($ max_file_size/1000000). "MB limit! </Font> ";
Unlink ($ file ["tmp_name"]);
Exit ();
}
// Check the file type
If (! In_array ($ file ["type"], $ uptypes ))
{
Echo "<font color = Red> the file type does not match! </Font> ";
Unlink ($ file ["tmp_name"]);
Exit ();
}
// Create the target folder
If (! File_exists ($ destination_folder ))
{
Mkdir ($ destination_folder );
}
$ Filename = $ file ["tmp_name"];
$ Pinfo = pathinfo ($ file ["name"]);
// Pathinfo () returns an array [dirname] [basename] [extension]
$ FTYPE = $ pinfo ['extension'];
// Remove the suffix of basename, which exists in $ name.
$ Pos = strrpos ($ pinfo ['basename'], ".");
$ Name = substr_replace ($ pinfo ['basename'], "", $ POs, strlen ($ pinfo ['basename']);
// Target file name path
$ Destination = $ destination_folder. $ name. "_". $ _ server ['remote _ ADDR ']. ".". $ FTYPE;
If (file_exists ($ destination) & $ overwrite! = True)
{
Echo "<font color = Red> a file with the same name already exists on the server. Please try again later! </Font> ";
Unlink ($ file ["tmp_name"]);
Exit ();
}
If (! Move_uploaded_file ($ filename, $ destination ))
{
Echo "<font color = Red> An error occurred while moving the file! </Font> ";
Exit ();
}
// Obtain the information of the moved object
$ Pinfo = pathinfo ($ destination );
$ Fname = $ pinfo [basename]; // basename is a file name without a path
Echo "<font color = Red> upload successful! </Font> <br> file name: <font color = blue> ". $ destination_folder. $ fname." </font> <br> ";
Echo "file size:". $ file ["size"]. "bytes ";
Echo "<br> submit IP Address:". $ _ server ['remote _ ADDR '];
}
?>
Of
Love J2EE follow Java Michael Jackson video station JSON online tools
Http://biancheng.dnbcw.info/php/340724.html pageno: 7.