php 多文件上传的实现实例_php实例

php中文网
发布: 2016-12-05 13:28:17
原创
1150人浏览过

首先向大家讲解一下实现的方法。

要实现多文件上传,我们可以在form表单中添加多个input file域,然后将这些input file的name属性设置为相同的名称且使用数组的形式命名,例如filename[]。至于文件上传的php代码和单个文件上传是一样的道理。

下面看一个多文件上传的实例:

html文件example.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<form action="my_parser.php" method="post" enctype="multipart/form-data">
 <p><input type="file" name="file_array[]"></p>
                    <div class="aritcle_card">
                        <a class="aritcle_card_img" href="/xiazai/code/11139">
                            <img src="https://img.php.cn/upload/webcode/000/000/009/176509801195970.png" alt="小邮包 包月订购包年程序">
                        </a>
                        <div class="aritcle_card_info">
                            <a href="/xiazai/code/11139">小邮包 包月订购包年程序</a>
                            <p>小邮包-包月订购包年服务网,该程序由好买卖商城开发,程序采用PHP+MYSQL架设,程序商业模式为目前最为火爆的包月订制包年服务模式,这种包年订购在国外网站已经热火很多年了,并且已经发展到一定规模,像英国的男士用品网站BlackSocks,一年的袜子购买量更是达到了1000万双。功能:1、实现多产品上线,2、不用注册也可以直接下单购买,3、集成目前主流支付接口,4、下单发货均有邮件提醒。</p>
                            <div class="">
                                <img src="/static/images/card_xiazai.png" alt="小邮包 包月订购包年程序">
                                <span>0</span>
                            </div>
                        </div>
                        <a href="/xiazai/code/11139" class="aritcle_card_btn">
                            <span>查看详情</span>
                            <img src="/static/images/cardxiayige-3.png" alt="小邮包 包月订购包年程序">
                        </a>
                    </div>
                <p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p>
 <p><input type="file" name="file_array[]"></p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p>
 <p><input type="file" name="file_array[]"></p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p>
 <input type="submit" value="Upload all files">
</form>
</body>
</html>
登录后复制

php文件my_parser.php

<&#63;php
if(isset($_FILES['file_array'])){
  $name_array = $_FILES['file_array']['name'];
  $tmp_name_array = $_FILES['file_array']['tmp_name'];
  $type_array = $_FILES['file_array']['type'];
  $size_array = $_FILES['file_array']['size'];
  $error_array = $_FILES['file_array']['error'];
  for($i = 0; $i < count($tmp_name_array); $i++){
    if(move_uploaded_file($tmp_name_array[$i], "test_uploads/".$name_array[$i])){
      echo $name_array[$i]." upload is complete<br>";
    } else {
      echo "move_uploaded_file function failed for ".$name_array[$i]."<br>";
    }
  }
}
&#63;>

登录后复制

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

相关标签:
php
PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号