Home > php教程 > php手册 > body text

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

WBOY
Release: 2016-06-13 11:06:01
Original
960 people have browsed it

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

<ol class="dp-xml">
<li class="alt"><span><strong><font color="#006699"><span class="tag"><span class="tag-name">html</span><span class="tag">></span></span></font></strong><span> </span></span></li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"><span class="tag-name">head</span><span class="tag">></span><span class="tag"><span class="tag-name">title</span><span class="tag">></span></span></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 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">form</span></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">></font></strong></span><span> </span>
</li>
<li class="alt">
<span>  </span><strong><font color="#006699"><span class="tag"><span class="tag-name">p</span><span class="tag">></span></span></font></strong><span>Pictures:</span><strong><font color="#006699"><span class="tag"><span class="tag-name">br</span></span></font></strong><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">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">"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 class="tag-name">br</span></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 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">"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 class="tag-name">br</span></span></font></strong><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">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">"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 class="tag-name">br</span></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 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">"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">/></font></strong></span><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>
</li>
<li class=""><span>if($_POST['upload']=='Send'){  </span></li>
<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>
</li>
<li class=""><span> if(!file_exists($dest_folder)){  </span></li>
<li class="alt"><span>        mkdir($dest_folder);  </span></li>
<li class=""><span> }  </span></li>
<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">></font></strong></span><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>
Copy after login

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


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template