Heim > Artikel > Backend-Entwicklung > 五分钟解决PHP上传文件代码演示_PHP教程
学习PHP时,你可能会遇到PHP上传文件问题,这里将介绍详细的PHP上传文件代码解决这个问题,在这里拿出来和大家分享一下。php的语法非常简单,正是它的简单性,使它成为了当前互联网第一编程语言。
<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上传文件代码,希望对大家有帮助。