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><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>
上記は詳細な PHP ファイルのアップロード コードです。皆様のお役に立てれば幸いです。