Uncover PHP Upload Image code detailed analysis _php tutorial

Source: Internet
Author: User
When learning PHP, you may encounter the PHP upload picture problem, here will introduce the detailed PHP upload image code to solve this problem, here to take out and share with you. PHP's syntax is very simple, it is the simplicity of it, making it the current Internet first programming language. You do not need to have a lot of knowledge to get started, such as: You learn C language, you must have a good understanding of how each variable is defined, how the pointer is manipulated, how memory is created and destroyed, and so on.

Another example: You learn the Java language, you must have an object-oriented (OO) Foundation, it must be clear when you need to encapsulate, when to inherit, when the need for polymorphism, to do the project, how to understand the point of SSH. Most users of PHP may not have so much to pay attention to, some people like process-oriented, you write code in a process-oriented way, some people like object-oriented, then you write code in an object-oriented way. PHP is due to the Internet, is currently the Internet Web2.0 first programming language. Meet user needs is always the first, maintainability can be placed in the second place. We often say that Web applications are always beta, and the plans are far from changing.

The following is the full PHP upload image code;

 
 
  1. < Formenctype Formenctype = "Multipart/form-data" Action ="" Method = "POST" >
  2. < InputType InputType = "hidden" name = "Max_file_size" value = "200000" >
  3. < InputName InputName = "UserFile" type = "File" >
  4. < InputType InputType = "Submit" name = "Submit" value = "Upload file" >
  5. form >
  6. PHP
  7. $ type = Array ("JPG", "gif", "BMP", "JPEG", "PNG");
  8. $ Uploaddir = "./file/" ;
  9. if (Isset ($_post[' submit '))
  10. {
  11. Functiontexttype ($name)
  12. {
  13. Returnsubstr (STRRCHR ($name, '. '), 1);
  14. }
  15. if (!in_array (Strtolower (Texttype ($_files[' userfile ' [' name '])), $type))
  16. {
  17. $ text = implode (",", $type);
  18. echo "You can only upload the following types of files:", $text, " < BR > ";
  19. }
  20. Else
  21. {
  22. if ($_files[' userfile ' [' Size ']<= "200000")
  23. {
  24. $ filename = Explode (".", $_files[' userfile ' [' name ']);
  25. $ Time = Date ("M-d-h-i-s");
  26. $filename [0]= $time;
  27. $ name = implode (".", $filename);
  28. $ UploadFile = $uploaddir. $name;
  29. if (Move_uploaded_file ($_files[' userfile ' [' tmp_name '], $uploadfile))
  30. {
  31. echo " < center > your file has been uploaded upload picture preview: !-- center > < BR > < center > < imgsrc imgsrc = ' $uploadfile ' > !-- center > ";
  32. echo " < BR > < Center > < Ahref Ahref = ' Javascrīpt:history.go ( -1) ' > Continue uploading a> Center>";
  33. }
  34. Else
  35. {
  36. echo "Transmission failed! ";
  37. }
  38. }
  39. Else
  40. {
  41. echo "Picture too big";
  42. }
  43. }
  44. }
  45. ?>

The above is the detailed PHP upload image code, we hope to be helpful.


http://www.bkjia.com/PHPjc/446552.html www.bkjia.com true http://www.bkjia.com/PHPjc/446552.html techarticle When learning PHP, you may encounter the PHP upload picture problem, here will introduce the detailed PHP upload image code to solve this problem, here to take out and share with you. PHP's syntax is very ...

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