分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

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

发布时间:2023-09-06 01:32责任编辑:赖小花关键词:上传图片

<!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 "头像未上传成功";
          }
      }

    

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

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

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved