Heim > php教程 > php手册 > Hauptteil

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

WBOY
Freigeben: 2016-06-13 11:06:01
Original
954 Leute haben es durchsucht

大家可以通过下面这一段代码,来具体了解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>
Nach dem Login kopieren

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


Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage