大家在通过对上传文件代码:
<ol class="dp-xml"> <li class="alt"><span><span><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"</SPAN><SPAN class=tag><STRONG><FONT color=#006699>></span><span> </span></span></li> <li class=""> <span></span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>html</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>xmlns</FONT></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>></span></font></strong><span> </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><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>meta</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>http-equiv</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"Content-Type"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>content</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"text/html; charset=gb2312"</FONT></SPAN><SPAN> </SPAN><SPAN class=tag><STRONG><FONT color=#006699>/></span></font></strong><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><SPAN class=tag-name>title</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class=""> <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="alt"> <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=""> <span></span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>mce:script</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>language</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"javascript"</FONT></SPAN><SPAN class=tag><STRONG><FONT color=#006699>></span></font></strong><span class="comments"><font color="#008200"><!-- </FONT></SPAN> </SPAN><LI class=alt><SPAN><SPAN class=comments><FONT color=#008200> 动态添加文件选择控件--></font></span><span> </span> </li> <li class=""><span> function AddRow() </span></li> <li class="alt"><span> { </span></li> <li class=""> <span> var </span><span class="attribute"><font color="#ff0000">eNewRow</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">tblData</font></span><span>.insertRow(); </span> </li> <li class="alt"> <span> for (var </span><span class="attribute"><font color="#ff0000">i</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">0</font></span><span>;i</span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>1</SPAN></FONT></STRONG><SPAN>;i++) </SPAN></SPAN><LI class=""><SPAN> { </SPAN><LI class=alt><SPAN> var </SPAN><SPAN class=attribute><FONT color=#ff0000>eNewCell</FONT></SPAN><SPAN> = </SPAN><SPAN class=attribute-value><FONT color=#0000ff>eNewRow</FONT></SPAN><SPAN>.insertCell(); </SPAN></SPAN><LI class=""><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>eNewCell.innerHTML</FONT></SPAN><SPAN> = </SPAN><SPAN class=attribute-value><FONT color=#0000ff>"<tr><td><input type='file' name='filelist[]' size='50'/></td></tr>"</span></font><span>; </span><li class="alt"><span> } </span></li> <li class=""><span> } </span></li> <li class="alt"><span> </span></li> <li class=""> <span>// --</span><strong><font color="#006699"><span class="tag">></span><span class="tag"></</SPAN><SPAN class=tag-name>mce:script</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class="alt"> <span></span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>form</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>name</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"myform"</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> </SPAN><SPAN class=attribute><FONT color=#ff0000>action</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"uploadfile.php"</FONT></SPAN><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=tag><STRONG><FONT color=#006699>></span></font></strong><span> </span> </li> <li class=""> <span> </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>table</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>id</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"tblData"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>width</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"400"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>border</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"0"</FONT></SPAN><SPAN class=tag><STRONG><FONT color=#006699>></span></font></strong><span> </span> </li> <li class="alt"> <span> </span><span class="comments"><font color="#008200"><!-- 将上传文件必须用post的方法和enctype="multipart/form-data" --></font></span><span> </span> </li> <li class=""><span> </span></li> <li class="alt"> <span> </span><span class="comments"><font color="#008200"><!-- 将本页的网址传给uploadfile.php--></font></span><span> </span> </li> <li class=""> <span> </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>input</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>name</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"postadd"</FONT></SPAN><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>value</FONT></SPAN><SPAN>="</SPAN><STRONG><FONT color=#006699><SPAN class=tag><?</SPAN><SPAN class=tag-name>php</SPAN></FONT></STRONG><SPAN> echo "</SPAN><SPAN class=attribute-value><FONT color=#0000ff>http</FONT></SPAN><SPAN>://".$_SERVER['HTTP_HOST'].$_SERVER["PHP_SELF"]; </SPAN><SPAN class=tag><STRONG><FONT color=#006699>?></span></font></strong><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>tr</SPAN><SPAN class=tag>></span><span class="tag"><</SPAN><SPAN class=tag-name>td</SPAN><SPAN class=tag>></span></font></strong><span>文件上传列表 </span> </li> <li class=""> <span> </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>input</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>type</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"button"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>name</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"addfile"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>onclick</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"AddRow()"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>value</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"添加列表"</FONT></SPAN><SPAN> </SPAN><STRONG><FONT color=#006699><SPAN class=tag>/></span><span class="tag"></</SPAN><SPAN class=tag-name>td</SPAN><SPAN class=tag>></span><span class="tag"></</SPAN><SPAN class=tag-name>tr</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class="alt"> <span> </span><span class="comments"><font color="#008200"><!-- filelist[]必须是一个数组--></font></span><span> </span> </li> <li class=""> <span> </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>tr</SPAN><SPAN class=tag>></span><span class="tag"><</SPAN><SPAN class=tag-name>td</SPAN><SPAN class=tag>></span><span class="tag"><</SPAN><SPAN class=tag-name>input</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>type</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"file"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>name</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"filelist[]"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>size</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"50"</FONT></SPAN><SPAN> </SPAN><STRONG><FONT color=#006699><SPAN class=tag>/></span><span class="tag"></</SPAN><SPAN class=tag-name>td</SPAN><SPAN class=tag>></span><span class="tag"></</SPAN><SPAN class=tag-name>tr</SPAN><SPAN class=tag>></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>table</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class="alt"> <span> </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>input</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>type</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"submit"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>name</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"submitfile"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>value</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"提交文件"</FONT></SPAN><SPAN> </SPAN><SPAN class=tag><STRONG><FONT color=#006699>/></span></font></strong><span> </span> </li> <li class=""> <span> </span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>form</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class="alt"> <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=""> <span></span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>html</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li></strong> </li> </ol>
PHP动态多文件上传之提交文件代码:
<ol class="dp-xml"> <li class="alt"><span><span><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<br>http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"</SPAN><SPAN class=tag><STRONG><FONT color=#006699>></span><span> </span></span></li> <li class=""> <span></span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>html</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>xmlns</FONT></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>></span></font></strong><span> </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><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>meta</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>http-equiv</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"Content-Type"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>content</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"text/html; charset=gb2312"</FONT></SPAN><SPAN> </SPAN><SPAN class=tag><STRONG><FONT color=#006699>/></span></font></strong><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><SPAN class=tag-name>title</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class=""> <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="alt"> <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=""> <span></span><strong><font color="#006699"><span class="tag"><?</SPAN><SPAN class=tag-name>php</SPAN></FONT></STRONG><SPAN> </SPAN></SPAN><LI class=alt><SPAN> if ($_POST["submitfile"]!="") </SPAN><LI class=""><SPAN> { </SPAN><LI class=alt><SPAN> $</SPAN><SPAN class=attribute><FONT color=#ff0000>Path</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"./"</FONT></SPAN><SPAN>.date('Ym')."/"; </SPAN></SPAN><LI class=""><SPAN> if (!is_dir($Path))//创建路径 </SPAN><LI class=alt><SPAN> { mkdir($Path); } </SPAN><LI class=""><SPAN> echo "</SPAN><STRONG><FONT color=#006699><SPAN class=tag><</SPAN><SPAN class=tag-name>div</SPAN><SPAN class=tag>></span></font></strong><span>"; </span> </li> <li class="alt"> <span> for ($</span><span class="attribute"><font color="#ff0000">i</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">0</font></span><span>;$i</span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>count</SPAN></FONT></STRONG><SPAN>($filelist);$i++) </SPAN></SPAN><LI class=""><SPAN> { //$_FILES["filelist"]["size"][$i]的排列顺序不可以变,<br>因为fileist是一个二维数组 </SPAN><LI class=alt><SPAN> if ($_FILES["filelist"]["size"][$i]!=0) </SPAN><LI class=""><SPAN> { </SPAN><LI class=alt><SPAN> $</SPAN><SPAN class=attribute><FONT color=#ff0000>File</FONT></SPAN><SPAN>=$Path.date('Ymdhm')."_".$_FILES["filelist"]["name"][$i]; </SPAN></SPAN><LI class=""><SPAN> if (move_uploaded_file($_FILES["filelist"]["tmp_name"][$i],$File)) </SPAN><LI class=alt><SPAN> { echo "文件上传成功 文件类型:".$_FILES["filelist"]<br>["type"][$i]." "."文件名:" </SPAN><LI class=""><SPAN> .$_FILES["filelist"]["name"][$i]."</SPAN><STRONG><FONT color=#006699><SPAN class=tag><</SPAN><SPAN class=tag-name>br</SPAN><SPAN class=tag>></span></font></strong><span>"; } </span> </li> <li class="alt"><span> else </span></li> <li class=""> <span> { echo "文件名:".$_FILES["filelist"]["name"][$i]."上传失败</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>br</SPAN><SPAN class=tag>></span></font></strong><span>"; } </span> </li> <li class="alt"><span> } </span></li> <li class=""><span> } </span></li> <li class="alt"> <span> echo "</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>div</SPAN><SPAN class=tag>></span><span class="tag"><</SPAN><SPAN class=tag-name>br</SPAN><SPAN class=tag>></span><span class="tag"><</SPAN><SPAN class=tag-name>a</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>href</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"$postadd"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>mce_href</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"$postadd"</FONT></SPAN><SPAN class=tag><STRONG><FONT color=#006699>></span></font></strong><span>返回</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>a</SPAN><SPAN class=tag>></span><span class="tag"></</SPAN><SPAN class=tag-name>div</SPAN><SPAN class=tag>></span></font></strong><span>"; </span> </li> <li class=""><span> } </span></li> <li class="alt"><span> </span></li> <li class=""> <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>body</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> <li class=""> <span></span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>html</SPAN><SPAN class=tag>></span></font></strong><span> </span> </li> </ol>
以上就是PHP动态多文件上传的所有代码。