When learning PHP, you may encounter the PHP Image Upload problem. Here we will introduce the PHP Image Upload code to solve this problem. Here we will share it with you. The syntax of php is very simple. It is its simplicity that makes it the first programming language on the Internet. You don't need to have a lot of knowledge to get started. For example, if you are learning C language, you must have a good understanding of how variables are defined, how pointers are operated, and how memory is created and destroyed.
For example, if you want to learn the Java language, you must have the foundation of object-oriented (OO). Then you must know when encapsulation is required, when inheritance is required, and when polymorphism is required, to do a project, you must understand SSH. Most PHP users may not be so specific at all. Some users prefer process-oriented, so you can write code in process-oriented mode. Some users prefer object-oriented, then you can write code in an object-oriented way. The emergence of Php is due to the Internet, and is currently the first programming language of Internet Web. Satisfying user needs is always the first, and maintainability can be placed in the second place. We usually say that Web applications are always beta, and the plan is far from changing rapidly.
The following is the complete PHP Image Upload code;
- <FormenctypeFormenctype= "Multipart/form-data"Action= ""Method="Post">
- <InputtypeInputtype= "Hidden"Name= "Max_file_size"Value="200000">
- <InputnameInputname= "Userfile"Type= "File">
- <InputtypeInputtype= "Submit"Name= "Submit"Value="Upload files">
- </Form>
-
- <?Php
- $Type=Array("Jpg", "gif", "bmp", "jpeg", "png ");
- $Uploaddir="./File /";
-
- If (isset ($ _ POST ['submit '])
- {
- Functiontexttype ($ name)
- {
- Returnsubstr (strrchr ($ name, '.'), 1 );
- }
- If (! In_array (strtolower (texttype ($ _ FILES ['userfile'] ['name']), $ type ))
- {
- $Text=Implode(",", $ Type );
- Echo "You can only upload the following types of files:", $ text ,"<Br>";
- }
- Else
- {
- If ($ _ FILES ['userfile'] ['SIZE']<= "200000 ")
- {
- $Filename=Explode(".", $ _ FILES ['userfile'] ['name']);
- $Time=Date("M-d-H-I-s ");
- $ Filename [0] = $ time;
- $Name=Implode(".", $ Filename );
- $Uploadfile= $ Uploaddir. $ name;
- If (move_uploaded_file ($ _ FILES ['userfile'] ['tmp _ name'], $ uploadfile ))
- {
- Echo"<Center>You have uploaded the file and uploaded the image to preview it:</Center><Br><Center><ImgsrcImgsrc='$ Uploadfile'></Center>";
- Echo"<Br><Center><AhrefAhref='Corruption Cr partition pt: history. go (-1 )'>Continue upload</A></Center>";
- }
- Else
- {
- Echo "transmission failed! ";
- }
- }
- Else
- {
- Echo "the image is too large ";
- }
- }
- }
- ?>
The above is the detailed PHP Image Upload code, which is helpful to you.