> 백엔드 개발 > PHP 튜토리얼 > PHP动态多文件上传的具体代码分享_PHP教程

PHP动态多文件上传的具体代码分享_PHP教程

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

大家在通过对上传文件代码:

<ol class="dp-xml">
<li class="alt"><span><span>nbsp;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">></font></strong></span><span>     </span></span></li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">html</span></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">></font></strong></span><span>     </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><strong><font color="#006699"><span class="tag"><span class="tag-name">meta</span></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">/></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><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 class="tag-name">body</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">mce:script</span></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">></font></strong></span><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 class="tag-name">1</span></span></font></strong><span>;i++)     </span>
</li>
<li class=""><span>    {     </span></li>
<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>
</li>
<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></td></tr>"</font></span><span>;     </span>
</li>
<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 class="tag-name">form</span></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">></font></strong></span><span>     </span>
</li>
<li class="">
<span>  </span><strong><font color="#006699"><span class="tag"><span class="tag-name">table</span></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">></font></strong></span><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 class="tag-name">input</span></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">?></font></strong></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">tr</span><span class="tag">></span><span class="tag"><span class="tag-name">td</span><span class="tag">></span></span></span></font></strong><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">"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 class="tag-name">tr</span><span class="tag">></span><span class="tag"><span class="tag-name">td</span><span class="tag">></span><span class="tag"><span class="tag-name">input</span></span></span></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 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">"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">/></font></strong></span><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>
</ol>
로그인 후 복사

PHP动态多文件上传之提交文件代码:

<ol class="dp-xml">
<li class="alt"><span><span>nbsp;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">></font></strong></span><span>     </span></span></li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">html</span></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">></font></strong></span><span>     </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><strong><font color="#006699"><span class="tag"><span class="tag-name">meta</span></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">/></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><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 class="tag-name">body</span><span class="tag">></span></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>
</li>
<li class="alt"><span>    if ($_POST["submitfile"]!="")     </span></li>
<li class=""><span>       {               </span></li>
<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>
</li>
<li class=""><span>         if (!is_dir($Path))//创建路径     </span></li>
<li class="alt"><span>             {  mkdir($Path);  }      </span></li>
<li class="">
<span>         echo "</span><strong><font color="#006699"><span class="tag"><span class="tag-name">div</span><span class="tag">></span></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 class="tag-name">count</span></span></font></strong><span>($filelist);$i++)     </span>
</li>
<li class=""><span>         { //$_FILES["filelist"]["size"][$i]的排列顺序不可以变,<br>因为fileist是一个二维数组     </span></li>
<li class="alt"><span>           if ($_FILES["filelist"]["size"][$i]!=0)      </span></li>
<li class=""><span>            {     </span></li>
<li class="alt">
<span>              $</span><span class="attribute"><font color="#ff0000">File</font></span><span>=$Path.date('Ymdhm')."_".$_FILES["filelist"]["name"][$i];     </span>
</li>
<li class=""><span>              if (move_uploaded_file($_FILES["filelist"]["tmp_name"][$i],$File))     </span></li>
<li class="alt"><span>                 { echo "文件上传成功 文件类型:".$_FILES["filelist"]<br>["type"][$i]." "."文件名:"    </span></li>
<li class="">
<span>                        .$_FILES["filelist"]["name"][$i]."</span><strong><font color="#006699"><span class="tag"><span class="tag-name">br</span><span class="tag">></span></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 class="tag-name">br</span><span class="tag">></span><span class="tag"><span class="tag-name">a</span></span></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">></font></strong></span><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动态多文件上传的所有代码。


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/446393.htmlTechArticle大家在通过对 上传文件代码: !DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" html xmlns = "http://www.w...
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿