Blogger Information
Blog 49
fans 0
comment 4
visits 41668
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
文件上传的原理与实现
过儿的博客
Original
830 people have browsed it

1、文件上传原理


1.png

2、文件上传  uploads.php

实例

<?php
   if($_SERVER['REQUEST_METHOD']){
       $allowed = ['image/jpeg','image/JPG','image/png'];
      $type = $_FILES['user_pic']['type'];
      $tmpName = $_FILES['user_pic']['tmp_name'];
      $name = $_FILES['user_pic']['name'];

      if(in_array($type,$allowed)){
          if(move_uploaded_file($tmpName,'./uploads/'.$name)){
              echo '<script>alert("上传成功")</script>';
          }
      }else{
        echo '<script>alert("文件类型错误")</script>';
      }
      $error = $_FILES['user_pic']['error'];
      if($error >0){
          echo '<script>alert("上传失败")</script>';
      }
   }
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <h2>上传头像</h2>
    <form method="post" enctype="multipart/form-data" action=" ">
       <input type="file" name="user_pic" id="user_pic">
       <button id="btn">上传</button>
    </form>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

1.png

Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post