码迷,mamicode.com
首页 > Web开发 > 详细

上传图片(阿贾克斯提交)

时间:2017-12-26 00:55:05      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:blog   成功   border   doc   pat   time()   multipart   input   har   

<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
 <title></title>
 <script src="jquery.js"></script>
</head>
<body>

   <form action="1.php" method="post" enctype="multipart/form-data" target="mywin">
     <input type="file" name="up_file">
     <!-- <input type="submit" name="btn" value="上传">
     <input type="hidden" name="path" value=""> -->
   </form>
   <div>
                <img   id="imgid" style="width: 100px;height: 100px; display: none;" >

            </div>
     <iframe   frameborder="1"  name="mywin" style="display:none;" src=""></iframe>
   
</body>
<script>
    $(document).ready(function(){
      $(":file").change(function(){
       $("form").submit();
      });
    });
</script>
<script>
 
</script>
</html>

 

 

 

 

<?php
 header(‘Content-type:text/html;charset="utf8"‘);
 // session_start();
      if(!is_dir(‘uploads‘)){
        mkdir(‘uploads‘);
      }
      $src=$_FILES[‘up_file‘][‘tmp_name‘];
      $file=$_FILES[‘up_file‘][‘name‘];
      $a=explode(‘.‘,$file);
      $ext=array_pop($a);
      $rand=time().mt_rand().‘.‘.$ext;
      $dst="uploads/{$rand}";
      if($_FILES[‘up_file‘][‘error‘]===0){
          if(move_uploaded_file($src,$dst)){
            
               echo "<script>imgid=window.top.document.getElementById(‘imgid‘);
              imgid.src=‘{$dst}‘</script>";
          }else{
              echo "头像未上传成功";
          }
      }

    

上传图片(阿贾克斯提交)

标签:blog   成功   border   doc   pat   time()   multipart   input   har   

原文地址:https://www.cnblogs.com/index0629/p/8111765.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!