学习PHP时,你可能会遇到PHP上传问题,这里将介绍PHP上传问题的解决方法,在这里拿出来和大家分享一下。本特性可以使用户上传文本和二进制文件。用 PHP 的认证和文件操作函数,可以完全控制允许哪些人上传以及文件上传后怎样处理PHP上传的文件。请注意 PHP 也支持 PUT 方法的文件上传,Netscape Composer 和 W3C 的 Amaya 客户端使用这种方法。
例子1. 文件上传表单
可以如下建立一个特殊的表单来支持文件上传:
<ol class="dp-xml"> <li class="alt"><span><span class="comments"><font color="#008200"><!-- The data encoding type, enctype, MUST be specified as below --></font></span><span> </span></span></li> <li class=""> <span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">form</span></span></font></strong><span> </span><span class="attribute"><font color="#ff0000">enctype</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"multipart/form-data"</font></span><span> </span><span class="attribute"><font color="#ff0000">action</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"__URL__"</font></span><span> </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="alt"> <span></span><span class="comments"><font color="#008200"><!-- MAX_FILE_SIZE must precede the file input field --></font></span><span> </span> </li> <li class=""> <span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">input</span></span></font></strong><span> </span><span class="attribute"><font color="#ff0000">type</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"hidden"</font></span><span> </span><span class="attribute"><font color="#ff0000">name</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"MAX_FILE_SIZE"</font></span><span> </span><span class="attribute"><font color="#ff0000">value</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">"30000"</font></span><span> </span><span class="tag"><strong><font color="#006699">/></font></strong></span><span> </span> </li> <li class="alt"><span></span></li> </ol>