五分钟解决PHP上传文件代码演示_PHP教程

WBOY
풀어 주다: 2016-07-15 13:27:07
원래의
809명이 탐색했습니다.

学习PHP时,你可能会遇到PHP上传文件问题,这里将介绍详细的PHP上传文件代码解决这个问题,在这里拿出来和大家分享一下。php的语法非常简单,正是它的简单性,使它成为了当前互联网第一编程语言。

你不需要具备很多的知识就能上手,比如:你学习C语言,就必须非常了解各个变量如何定义,指针如何操作,内存如何创建销毁等等。再比如:你学习Java语言,就必须具有面向对象(OO)的基础,就必须清楚是什么时候需要封装,什么时候需要继承,什么时候需要多态,要做项目,怎么还得懂点SSH。PHP的大部分使用者可能根本就没这么多讲究,有的人喜欢面向过程,那你就用面向过程的方式来写代码;有的人喜欢面向对象,那你就用面向对象的方式写代码。Php的产生缘于互联网,目前也是互联网Web2.0第一编程语言。满足用户需求永远是第一位的,可维护性暂且可以放在第二位。我们通常说Web应用永远是β版的,计划远没有变化快。
<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 class="tag-name">head</span><span class="tag">></span></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 class="tag-name">title</span><span class="tag">></span></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 class="tag-name">body</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 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 class="tag-name">pre</span><span class="tag">></span></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>
로그인 후 복사

以上就是详细的PHP上传文件代码,希望对大家有帮助。


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/446553.htmlTechArticle学习PHP时,你可能会遇到PHP上传文件问题,这里将介绍详细的PHP上传文件代码解决这个问题,在这里拿出来和大家分享一下。php的语法非常...
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿