Rumah  >  Artikel  >  pembangunan bahagian belakang  >  PHP动态多文件上传的具体代码分享_PHP教程

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

WBOY
WBOYasal
2016-07-15 13:29:18832semak imbas

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

<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...
Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn