1

  1. <?php
  2. // printf('<pre>%s</pre>',print_r($_FILES,true));
  3. // 1. 实例演示单文件上传与多文件上传
  4. // 单文件
  5. if(isset($_FILES['myfile'])){
  6. extract($_FILES['myfile']);
  7. if($error===0){
  8. $ext = pathinfo($name)['extension'];
  9. $dest = 'uploads/'. md5($name) . '.' . $ext;
  10. if(move_uploaded_file($tmp_name,$dest)){
  11. echo '<span style="color:green">上传成功</span><br>';
  12. echo "<img src=$dest width='200'>";
  13. }
  14. }
  15. }
  16. ?>
  17. <!DOCTYPE html>
  18. <html lang="en">
  19. <head>
  20. <meta charset="UTF-8">
  21. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  22. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  23. <title>单文件上传</title>
  24. </head>
  25. <body>
  26. <form action="" method="post" enctype="multipart/form-data">
  27. <fieldset>
  28. <legend>单文件上传</legend>
  29. <input type="file" name="myfile">
  30. <button>上传</button>
  31. </fieldset>
  32. </form>
  33. </body>
  34. </html>

2

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

3

  1. <?php
  2. $p = $_GET['p']??1;
  3. // 2. 实例演示简单分页操作,并理解分页所需参数的意思
  4. $db = new PDO('mysql:dbname=phpedu','root','root');
  5. // 数据表总数量:Total
  6. $sql = 'SELECT COUNT(*) AS `total` FROM `staff`';
  7. $stmt = $db->prepare($sql);
  8. $stmt->execute();
  9. $stmt->bindColumn('total', $total);
  10. $stmt->fetch(PDO::FETCH_ASSOC);
  11. // 单页显示数量:num=5
  12. $num = 5;
  13. // 分页数量
  14. $pages = ceil($total/$num);
  15. // 计算偏移量
  16. $offset = ($p-1)*$num;
  17. $sql = "SELECT * FROM `staff` LIMIT $num OFFSET $offset";
  18. $stmt = $db->prepare($sql);
  19. $stmt->execute();
  20. $staffs = $stmt->fetchAll(PDO::FETCH_ASSOC);
  21. ?>
  22. <!DOCTYPE html>
  23. <html lang="en">
  24. <head>
  25. <meta charset="UTF-8">
  26. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  27. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  28. <title>分页操作</title>
  29. <style>
  30. table {
  31. width: 400px;
  32. border-collapse: collapse;
  33. text-align: center;
  34. }
  35. table th,
  36. table td {
  37. border: 1px solid;
  38. padding: 5px;
  39. }
  40. table thead {
  41. background-color: lightcyan;
  42. }
  43. table caption {
  44. font-size: larger;
  45. margin-bottom: 8px;
  46. }
  47. p>a {
  48. text-decoration: none;
  49. color: #555;
  50. border: 1px solid;
  51. padding: 5px 10px;
  52. margin: 10px 2px;
  53. }
  54. .active {
  55. background-color: seagreen;
  56. color: white;
  57. border: 1px solid seagreen;
  58. }
  59. </style>
  60. </head>
  61. <body>
  62. <table>
  63. <caption>员工信息表</caption>
  64. <thead>
  65. <tr>
  66. <th>ID</th>
  67. <th>姓名</th>
  68. <th>性别</th>
  69. <th>邮箱</th>
  70. </tr>
  71. </thead>
  72. <tbody>
  73. <?php foreach ($staffs as $staff) : extract($staff) ?>
  74. <tr>
  75. <td><?= $id ?></td>
  76. <td><?= $name ?></td>
  77. <td><?= $gender ?></td>
  78. <td><?= $email ?></td>
  79. </tr>
  80. <?php endforeach ?>
  81. </tbody>
  82. </table>
  83. <p>
  84. <?php for ($i = 1; $i <= $pages; $i++) : ?>
  85. <?php
  86. $url = $_SERVER['PHP_SELF'] . '?p=' . $i;
  87. $active = $i == $_GET['p'] ? 'active' : null;
  88. ?>
  89. <a href="<?= $url ?>" class="<?= $active ?>"><?= $i ?></a>
  90. <?php endfor ?>
  91. </p>
  92. </body>
  93. </html>

更多相关文章

  1. 双击运行Android模拟器、创建SDcard、AVD、安装APK文件、上传文
  2. Android自动打包、签名、优化、上传ANT脚本
  3. Android(安卓)实现文件上传功能(upload)
  4. Android文件图片上传的详细讲解(三)---模式回调类
  5. Android文件夹大小
  6. android gps经纬度实时更新,获取卫星数量
  7. android照相及照片上传
  8. Android上传图片裁剪功能
  9. JSP实现文件上传功能

随机推荐

  1. js字符串与html代码互相转换时怪想法:自
  2. 设计不是使用跨度和按钮
  3. Nodejs中利用phantom把html转为pdf或图片
  4. 图标旋转但返回上一个位置
  5. CSS定位属性之间的相互作用
  6. 动画滚动无法在Firefox中运行?
  7. HTML5 Canvas编写五彩连珠(3):设计
  8. HTML:关于a标签的target属性
  9. 当锚标记被单击时,角值从一个页面传递到另
  10. jQuery .load停止嵌入页面/重新加载整个