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;
- < Formenctype Formenctype = "Multipart/form-data" Action ="" Method = "POST" >
- < InputType InputType = "hidden" name = "Max_file_size" value = "200000" >
- < InputName InputName = "UserFile" type = "File" >
- < InputType InputType = "Submit" name = "Submit" value = "Upload file" >
- 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 > your file has been uploaded upload picture preview: !-- center > < BR > < center > < imgsrc imgsrc = ' $uploadfile ' > !-- center > ";
- echo " < BR > < Center > < Ahref Ahref = ' Javascrīpt:history.go ( -1) ' > Continue uploading a> Center>";
- }
- Else
- {
- echo "Transmission failed! ";
- }
- }
- Else
- {
- echo "Picture too big";
- }
- }
- }
- ?>
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 ...