Actual combat php Upload file code demo _php Tutorial

Source: Internet
Author: User
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

 
 
  1. < HTML > < Head >
  2. < title > uploading a file form title> head >
  3. < Body >
  4. < form enctype="multipart/form-data" action="" method = "POST" >
  5. Please select a file: < BR >
  6. < input name="upload_file" type="file" ><br>
  7. < input type="Submit" value="Upload file" >
  8. form >
  9. Body >
  10. HTML >
  11. $ Upload_file =$_files[' upload_file ' [' tmp_name '];
  12. $ Upload_file_name =$_files[' upload_file ' [' name '];
  13. if ($upload _file) {
  14. $ File_size_max = + *1000;//1M limit file upload maximum capacity (bytes)
  15. $ Store_dir = "d:/" ;//storage location of uploaded files
  16. $ Accept_overwrite = 1 ;//whether to allow overwriting of the same file
  17. Check File size
  18. if ($upload _file_size > $file _size_max) {
  19. echo "Sorry, your file size is greater than the provision";
  20. Exit
  21. }
  22. Check read and write files
  23. if (file_exists ($store _dir. $upload _file_name) && $accept _overwrite) {
  24. Echo "file with the same file name exists";
  25. Exit
  26. }
  27. Copy files to the specified directory
  28. if (!move_uploaded_file ($upload _file, $store _dir. $upload _file_name)) {
  29. echo "Failed to copy file";
  30. Exit
  31. }
  32. }
  33. Echo " < P > you uploaded the file: ";
  34. echo$_files[' upload_file ' [' name '];
  35. echo " < BR > ";
  36. The original name of the client machine file.
  37. Echo "file has a MIME type of:";
  38. echo $_files[' upload_file ' [' type '];
  39. The MIME type of the file requires the browser to provide support for that information, such as "Image/gif".
  40. echo " < BR > ";
  41. Echo "Upload file size:";
  42. echo $_files[' upload_file ' [' Size '];
  43. The size of the uploaded file, in bytes.
  44. echo " < BR > ";
  45. Echo "file was temporarily stored as:" After uploading;
  46. echo $_files[' upload_file ' [' tmp_name '];
  47. Temporary file names stored on the server after the files have been uploaded.
  48. echo " < BR > ";
  49. $ Erroe =$_files[' upload_file ' [' Error '];
  50. Switch ($Erroe) {
  51. Case 0:
  52. Echo "Upload success"; Break
  53. Case 1:
  54. Echo "uploaded a file that exceeds the value of the Upload_max_filesize option limit in php.ini."; Break
  55. Case 2:
  56. Echo "The size of the uploaded file exceeds the value specified by the Max_file_size option in the HTML form. "; break;
  57. Case 3:
  58. Echo "file is only partially uploaded";
  59. Case 4:
  60. Echo "No files were uploaded";
  61. }
  62. ?>


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

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