搜索
博主信息
博文 21
粉丝 0
评论 0
访问量 16565
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
多文件上传
原创
593人浏览过

方式1代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <?php
  4. foreach ($_FILES as $file) {
  5. if ($file['error'] === 0) {
  6. $destFile = 'uploads/' . $file['name'];
  7. move_uploaded_file($file['tmp_name'],$destFile);
  8. echo "<img src='$destFile' width='230'>";
  9. }
  10. }
  11. ?>
  12. <head>
  13. <meta charset="UTF-8">
  14. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  15. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  16. <title>多文件上传</title>
  17. <style>
  18. .upload {
  19. display: grid;
  20. grid-template-columns: repeat(1,1fr);
  21. gap: 3vw;
  22. padding: 0 15%;
  23. }
  24. .upload button {
  25. width: 120px;
  26. }
  27. </style>
  28. </head>
  29. <body>
  30. <form action="" method="POST" enctype="multipart/form-data">
  31. <fieldset class="upload">
  32. <legend>多文件上传:逐个上传</legend>
  33. <input type="file" name="mydoc1">
  34. <input type="file" name="mydoc2">
  35. <input type="file" name="mydoc3">
  36. <button>上传</button>
  37. </fieldset>
  38. </form>
  39. </body>
  40. </html>

方式2代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <?php
  4. printf('<pre>%s</pre>', print_r($_FILES, true));
  5. if (isset($_FILES['mypic'])) {
  6. foreach ($_FILES['mypic']['error'] as $key => $error) {
  7. if ($error === 0) {
  8. $tmpName = $_FILES['mypic']['tmp_name'][$key];
  9. $name = $_FILES['mypic']['name'][$key];
  10. $destFile = 'uploads/' . $name;
  11. move_uploaded_file($tmpName,$destFile);
  12. echo "<img src='$destFile' width='240'>";
  13. }
  14. }
  15. }
  16. ?>
  17. <head>
  18. <meta charset="UTF-8">
  19. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  20. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  21. <title>Document多文件上传2</title>
  22. </head>
  23. <body>
  24. <form action="" method="POST" enctype="multipart/form-data">
  25. <fieldset>
  26. <legend>多文件上传:逐个上传2</legend>
  27. <input type="file" name="mypic[]">
  28. <input type="file" name="mypic[]">
  29. <input type="file" name="mypic[]">
  30. <button>上传</button>
  31. </fieldset>
  32. </form>
  33. </body>
  34. </html>

方式3代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <?php
  4. printf('<pre>%s</pre>', print_r($_FILES, true));
  5. if (isset($_FILES['mypic'])) {
  6. foreach ($_FILES['mypic']['error'] as $key => $error) {
  7. if ($error === 0) {
  8. $tmpName = $_FILES['mypic']['tmp_name'][$key];
  9. $name = $_FILES['mypic']['name'][$key];
  10. $destFile = 'uploads/' . $name;
  11. move_uploaded_file($tmpName,$destFile);
  12. echo "<img src='$destFile' width='240'>";
  13. }
  14. }
  15. }
  16. ?>
  17. <head>
  18. <meta charset="UTF-8">
  19. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  20. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  21. <title>Document多文件上传3</title>
  22. </head>
  23. <body>
  24. <form action="" method="POST" enctype="multipart/form-data">
  25. <fieldset>
  26. <legend>多文件上传:批量上传</legend>
  27. <input type="file" name="mypic[]" multiple>
  28. <button>上传</button>
  29. </fieldset>
  30. </form>
  31. </body>
  32. </html>
批改老师:PHPzPHPz

批改状态:合格

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

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

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学