PHP after a long period of development, many users are very familiar with PHP, here I publish a PHP upload file code, and we discuss the discussion. PHP itself is a simple and powerful language. The PHP language has core features such as powerful string and array processing capabilities, while greatly improving the support for object-oriented programming (PHP5 and above). By using standard and optional extensions, PHP applications can connect more than 10 databases such as MySQL or Oracle, draw, create PDF files, and create parsing XML files. You can also use the C language to write your own PHP extension module.
For example, provide an interface function for PHP in a code base that already exists. You can also run PHP under Windows, use COM to control other Windows applications such as Word and Excel, or use ODBC to connect to a database. At home, PHP once and Microsoft's ASP, is commonly used in network programming language. ASP3.0 now has been abandoned by Microsoft, no longer updated, perhaps some people will think: PHP should be a fast-dying thing, right? However, contrary to the fact, PHP not only in the rapid development, the ASP far behind, and gradually become the Internet is now the most widely used, the most popular language.
PHP Upload file code
- < HTML > < Head >
- < title > uploading a file form title> head >
- < Body >
- < form enctype="multipart/form-data" action="" method = "POST" >
- Please select a file: < BR >
- < input name="upload_file" type="file" ><br>
- < input type="Submit" value="Upload file" >
- form >
- Body >
- HTML >
-
- $ Upload_file =$_files[' upload_file ' [' tmp_name '];
- $ Upload_file_name =$_files[' upload_file ' [' name '];
- if ($upload _file) {
- $ File_size_max = + *1000;//1M limit file upload maximum capacity (bytes)
- $ Store_dir = "d:/" ;//storage location of uploaded files
- $ Accept_overwrite = 1 ;//whether to allow overwriting of the same file
- Check File size
- if ($upload _file_size > $file _size_max) {
- echo "Sorry, your file size is greater than the provision";
- Exit
- }
- Check read and write files
- if (file_exists ($store _dir. $upload _file_name) && $accept _overwrite) {
- Echo "file with the same file name exists";
- Exit
- }
- Copy files to the specified directory
- if (!move_uploaded_file ($upload _file, $store _dir. $upload _file_name)) {
- echo "Failed to copy file";
- Exit
- }
- }
- Echo " < P > you uploaded the file: ";
- echo$_files[' upload_file ' [' name '];
- echo " < BR > ";
- The original name of the client machine file.
- Echo "file has a MIME type of:";
- echo $_files[' upload_file ' [' type '];
- The MIME type of the file requires the browser to provide support for that information, such as "Image/gif".
- echo " < BR > ";
- Echo "Upload file size:";
- echo $_files[' upload_file ' [' Size '];
- The size of the uploaded file, in bytes.
- echo " < BR > ";
- Echo "file was temporarily stored as:" After uploading;
- echo $_files[' upload_file ' [' tmp_name '];
- Temporary file names stored on the server after the files have been uploaded.
- echo " < BR > ";
- $ Erroe =$_files[' upload_file ' [' Error '];
- Switch ($Erroe) {
- Case 0:
- Echo "Upload success"; Break
- Case 1:
- Echo "uploaded a file that exceeds the value of the Upload_max_filesize option limit in php.ini."; Break
- Case 2:
- Echo "The size of the uploaded file exceeds the value specified by the Max_file_size option in the HTML form. "; break;
- Case 3:
- Echo "file is only partially uploaded";
- Case 4:
- Echo "No files were uploaded";
- }
- ?>
The above is the detailed PHP upload file code, we hope to be helpful.
http://www.bkjia.com/PHPjc/446559.html www.bkjia.com true http://www.bkjia.com/PHPjc/446559.html techarticle PHP After a long period of development, many users are very familiar with PHP, here I publish a PHP upload file code, and we discuss the discussion. PHP itself is a simple and powerful language. PHP language ...