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

WBOY
リリース: 2016-06-13 11:06:01
オリジナル
953 人が閲覧しました

大家可以通过下面这一段代码,来具体了解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>
ログイン後にコピー

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


ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のおすすめ
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート