首页 > php教程 > php手册 > 正文

PHP批量上传图片的具体实现方式

WBOY
发布: 2016-06-13 11:06:01
原创
959 人浏览过

大家可以通过下面这一段代码,来具体了解PHP批量上传图片的具体方式。我们在学习PHP批量上传图片的代码如下:

<ol class="dp-xml">
<li class="alt"><span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>html</SPAN><SPAN class=tag>></span></font></strong><span> </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><span class="tag"><</SPAN><SPAN class=tag-name>title</SPAN><SPAN class=tag>></span></font></strong><span>upload picture more once</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>title</SPAN><SPAN class=tag>></span><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>form</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>action</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>""</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>enctype</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"multipart/form-data"</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>p</SPAN><SPAN class=tag>></span></font></strong><span>Pictures:</span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>br</SPAN></FONT></STRONG><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>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>"pictures[]"</FONT></SPAN><SPAN> </SPAN><STRONG><FONT color=#006699><SPAN class=tag>/></span><span class="tag"><</SPAN><SPAN class=tag-name>br</SPAN></FONT></STRONG><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>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>"pictures[]"</FONT></SPAN><SPAN> </SPAN><STRONG><FONT color=#006699><SPAN class=tag>/></span><span class="tag"><</SPAN><SPAN class=tag-name>br</SPAN></FONT></STRONG><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>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>"pictures[]"</FONT></SPAN><SPAN> </SPAN><STRONG><FONT color=#006699><SPAN class=tag>/></span><span class="tag"><</SPAN><SPAN class=tag-name>br</SPAN></FONT></STRONG><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>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>"upload"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>value</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"Send"</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>p</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><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>body</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>html</SPAN><SPAN class=tag>></span></font></strong><span> </span>
</li>
<li class=""><span> </span></li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"><?</SPAN><SPAN class=tag-name>php</SPAN></FONT></STRONG><SPAN> </SPAN></SPAN><LI class=""><SPAN>if($_POST['upload']=='Send'){  </SPAN><LI class=alt><SPAN>    $</SPAN><SPAN class=attribute><FONT color=#ff0000>dest_folder</FONT></SPAN><SPAN>   =  </SPAN><SPAN class=attribute-value><FONT color=#0000ff>"picture/"</FONT></SPAN><SPAN>;  </SPAN></SPAN><LI class=""><SPAN> if(!file_exists($dest_folder)){  </SPAN><LI class=alt><SPAN>        mkdir($dest_folder);  </SPAN><LI class=""><SPAN> }  </SPAN><LI class=alt><SPAN> foreach ($_FILES["pictures"]["error"] as $</SPAN><SPAN class=attribute><FONT color=#ff0000>key</FONT></SPAN><SPAN> =</SPAN><SPAN class=tag><STRONG><FONT color=#006699>></span></font></strong><span> $error) {  </span>
</li>
<li class="">
<span>     if ($</span><span class="attribute"><font color="#ff0000">error</font></span><span> == UPLOAD_ERR_OK) {  </span>
</li>
<li class="alt">
<span>         $</span><span class="attribute"><font color="#ff0000">tmp_name</font></span><span> = $_FILES["pictures"]["tmp_name"][$key];  </span>
</li>
<li class="">
<span>         $</span><span class="attribute"><font color="#ff0000">name</font></span><span>    = $_FILES["pictures"]["name"][$key];  </span>
</li>
<li class="alt">
<span>      $</span><span class="attribute"><font color="#ff0000">uploadfile</font></span><span> = $dest_folder.$name;  </span>
</li>
<li class=""><span>         move_uploaded_file($tmp_name, $uploadfile);  </span></li>
<li class="alt"><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>
</ol>
登录后复制

以上代码就是PHP批量上传图片的全部编程,希望对有需要的同学有所帮助。


来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板