Five minutes to solve PHP file upload code demonstration_PHP tutorial

WBOY
Release: 2016-07-15 13:27:07
Original
812 people have browsed it

When learning PHP, you may encounter the problem of uploading files in PHP. Here we will introduce the detailed PHP file upload code to solve this problem. I will share it with you here. The syntax of PHP is very simple. It is its simplicity that makes it the number one programming language on the Internet.

You don’t need to have a lot of knowledge to get started. For example, if you learn C language, you must know how to define each variable, how to operate pointers, and memory. How to create and destroy etc. Another example: when you learn the Java language, you must have a foundation in object-oriented (OO), and you must know when encapsulation is needed, when inheritance is needed, and when polymorphism is needed. To do a project, why do you need to know SSH. Most users of PHP may not be so particular at all. Some people like process-oriented, so you should write code in a process-oriented way; some people like object-oriented, then you should write code in an object-oriented way. . Php originated from the Internet, and it is currently the first programming language of Web2.0 on the Internet. Meeting user needs always comes first, and maintainability can be placed second for now. We usually say that web applications will always be beta versions, and plans are far less likely to change quickly.
<ol class="dp-xml">
<li class="alt"><span><span><span class="tag"><strong><font color="#006699">></font></strong></span><span> </span></span><li class="">
<span></span><span class="tag"><strong><font color="#006699"><</FONT></STRONG></SPAN><SPAN class=attribute><FONT color=#ff0000>htmlxmlns</FONT></SPAN><SPAN class=tag-name><STRONG><FONT color=#006699>htmlxmlns</FONT></STRONG></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"http://www.w3.org/1999/xhtml"</FONT></SPAN><SPAN class=tag><STRONG><FONT color=#006699>></font></strong></span><span> </span>
</li></span></li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>head</SPAN><SPAN class=tag>></span></font></strong><span> </span>
</li>
<li class="">
<span></span><span class="tag"><strong><font color="#006699"><</FONT></STRONG></SPAN><SPAN class=attribute><FONT color=#ff0000>metahttp-equiv</FONT></SPAN><SPAN class=tag-name><STRONG><FONT color=#006699>metahttp-equiv</FONT></STRONG></SPAN><SPAN>="Content-Type"</SPAN><SPAN class=attribute-value><FONT color=#0000ff>content</FONT></SPAN><SPAN>="text/html;</SPAN><SPAN class=attribute><FONT color=#ff0000>charset</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>gb2312</FONT></SPAN><SPAN>"</SPAN><SPAN class=tag><STRONG><FONT color=#006699>/></font></strong></span><span> </span>
</li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>title</SPAN><SPAN class=tag>></span></font></strong><span>无标题文档</span><strong><font color="#006699"><span class="tag"><span class="tag-name">title</span><span class="tag">></span></span></font></strong><span> </span>
</li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">head</span><span class="tag">></span></span></font></strong><span> </span>
</li>
<li class="alt"><span> </span></li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>body</SPAN><SPAN class=tag>></span></font></strong><span> </span>
</li>
<li class="alt">
<span></span><span class="tag"><strong><font color="#006699"><</FONT></STRONG></SPAN><SPAN class=attribute><FONT color=#ff0000>formenctype</FONT></SPAN><SPAN class=tag-name><STRONG><FONT color=#006699>formenctype</FONT></STRONG></SPAN><SPAN>="multipart/form-data"</SPAN><SPAN class=attribute-value><FONT color=#0000ff>action</FONT></SPAN><SPAN>="upload.php"</SPAN><SPAN class=attribute><FONT color=#ff0000>method</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"post"</FONT></SPAN><SPAN class=tag><STRONG><FONT color=#006699>></font></strong></span><span> </span>
</li>
<li class="">
<span></span><span class="tag"><strong><font color="#006699"><</FONT></STRONG></SPAN><SPAN class=attribute><FONT color=#ff0000>inputtype</FONT></SPAN><SPAN class=tag-name><STRONG><FONT color=#006699>inputtype</FONT></STRONG></SPAN><SPAN>="hidden"</SPAN><SPAN class=attribute-value><FONT color=#0000ff>name</FONT></SPAN><SPAN>="max_file_size"</SPAN><SPAN class=attribute><FONT color=#ff0000>value</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>300000</FONT></SPAN><SPAN class=tag><STRONG><FONT color=#006699>></font></strong></span><span> </span>
</li>
<li class="alt">
<span></span><span class="tag"><strong><font color="#006699"><</FONT></STRONG></SPAN><SPAN class=attribute><FONT color=#ff0000>inputname</FONT></SPAN><SPAN class=tag-name><STRONG><FONT color=#006699>inputname</FONT></STRONG></SPAN><SPAN>="userfile"</SPAN><SPAN class=attribute-value><FONT color=#0000ff>type</FONT></SPAN><SPAN>="file"</SPAN><SPAN class=tag><STRONG><FONT color=#006699>></font></strong></span><span> </span>
</li>
<li class="">
<span></span><span class="tag"><strong><font color="#006699"><</FONT></STRONG></SPAN><SPAN class=attribute><FONT color=#ff0000>inputtype</FONT></SPAN><SPAN class=tag-name><STRONG><FONT color=#006699>inputtype</FONT></STRONG></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"submit"</FONT></SPAN><SPAN class=tag><STRONG><FONT color=#006699>></font></strong></span><span> </span>
</li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">form</span><span class="tag">></span></span></font></strong><span> </span>
</li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">body</span><span class="tag">></span></span></font></strong><span> </span>
</li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">html</span><span class="tag">></span></span></font></strong><span> </span>
</li>
<li class=""><span> </span></li>
<li class="alt"><span>//upload.php  </span></li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">php</span></font></strong><span> </span>
</li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">uploaddir</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"c:\"</font></span><span>;  </span>
</li>
<li class="">
<span>$</span><span class="attribute"><font color="#ff0000">uploadfile</font></span><span>=$uploaddir.$_FILES['userfile']['name'];  </span>
</li>
<li class="alt">
<span>print"</span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>pre</SPAN><SPAN class=tag>></span></font></strong><span>";  </span>
</li>
<li class=""><span>if(move_uploaded_file($_FILES['userfile']['tmp_name'],$uploadfile))  </span></li>
<li class="alt"><span>{  </span></li>
<li class=""><span>print("上传成功!");  </span></li>
<li class="alt"><span>print_r($_FILES);  </span></li>
<li class=""><span>}  </span></li>
<li class="alt"><span>else  </span></li>
<li class=""><span>{  </span></li>
<li class="alt"><span>print("上传失败!");  </span></li>
<li class=""><span>print_r($_FILES);  </span></li>
<li class="alt"><span>}  </span></li>
<li class="">
<span>print"</span><strong><font color="#006699"><span class="tag"><span class="tag-name">pre</span><span class="tag">></span></span></font></strong><span>";  </span>
</li>
<li class="alt">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span>
</li>
</ol>
Copy after login

The above is the detailed PHP file upload code, I hope it will be helpful to everyone.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446553.htmlTechArticleWhen learning PHP, you may encounter problems with PHP uploading files. Here we will introduce the detailed code solution for PHP uploading files. I would like to share this question with you here. The syntax of php is very...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template