PHP file upload code demo _ PHP Tutorial

Source: Internet
Author: User
Tags php file upload
Demo of PHP file upload code. PHP has been developing for a long time and many users are familiar with PHP. here I will share the PHP file upload code and discuss it with you. PHP itself is a simple and powerful language. PHP language PHP has been developing for a long time and many users are familiar with PHP. here I will share the PHP file upload code and discuss it with you. PHP itself is a simple and powerful language. PHP has core features such as powerful string and array processing capabilities, and greatly improved support for object-oriented programming (PHP5 and later versions ). Using standard and optional extension modules, PHP applications can connect to more than a dozen databases such as MySQL or Oracle, draw, create PDF files, and create parsed XML files. You can also use the C language to write your own PHP extension module.

For example, provide a PHP interface function in an existing code library. You can also run PHP in Windows, use COM to control other Windows applications such as Word and Excel, or use ODBC to connect to the database. In China, PHP is a commonly used network programming language. ASP3.0 has already been abandoned by Microsoft and will not be updated any more. some people may think that PHP should also be something that will soon become a new thing, right? However, on the contrary, PHP is not only developing rapidly, but also leaving ASP far behind. it is gradually becoming the most widely used and popular language on the Internet.

PHP file upload code

 
 
  1. <Html><Head>
  2. <Title>Upload file Form Title> Head>
  3. <Body>
  4. <Form Enctype="Multipart/form-data" Action="" Method="Post">
  5. Select a file:<Br>
  6. <Input Name="Upload_file" Type="File"><Br>
  7. <Input Type="Submit" Value="Upload files">
  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* 1000; // 1 MB limit the maximum file upload capacity (bytes)
  15. $Store_dir="D :/"; // Storage location of uploaded files
  16. $Accept_overwrite=1; // Whether to overwrite the same file
  17. // Check the file size
  18. If ($ upload_file_size>$ File_size_max ){
  19. Echo "Sorry, your file capacity exceeds the limit ";
  20. Exit;
  21. }
  22. // Check the read/write file
  23. If (file_exists ($ store_dir. $ upload_file_name )&&! $ Accept_overwrite ){
  24. Echo "files with the same file name exist ";
  25. Exit;
  26. }
  27. // Copy the file to the specified directory
  28. If (! Move_uploaded_file ($ upload_file, $ store_dir. $ upload_file_name )){
  29. Echo "failed to copy the 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 "the MIME type of the file is :";
  38. Echo $ _ FILES ['upload _ file'] ['type'];
  39. // MIME type of the file, which must be supported by the browser, for example, "image/gif ".
  40. Echo"<Br>";
  41. Echo "Upload file size :";
  42. Echo $ _ FILES ['upload _ file'] ['size'];
  43. // Size of the uploaded file, in bytes.
  44. Echo"<Br>";
  45. Echo "the file is temporarily stored after being uploaded :";
  46. Echo $ _ FILES ['upload _ file'] ['tmp _ name'];
  47. // Temporary file name stored on the server after the file is uploaded.
  48. Echo"<Br>";
  49. $Erroe= $ _ FILES ['upload _ file'] ['error'];
  50. Switch ($ Erroe ){
  51. Case 0:
  52. Echo "uploaded successfully"; break;
  53. Case 1:
  54. Echo "the uploaded file exceeds the limit of the upload_max_filesize option 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 "only part of the file is uploaded"; break;
  59. Case 4:
  60. Echo "no file is uploaded"; break;
  61. }
  62. ?>


The above is the detailed PHP file upload code, and I hope to help you.


Bytes. PHP itself is a simple and powerful language. PHP...

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.