PHP:

<?php
/**
* Created by PhpStorm.
* User: DELL
* Date: 2017/11/23
* Time: 10:57
*/
header("Access-Control-Allow-Origin:*");
// 响应类型
header('Access-Control-Allow-Methods:POST');
// 响应头设置
header('Access-Control-Allow-Headers:x-requested-with, content-type');
header("Content-type: text/html; charset=utf-8");
$file = $_FILES["file"];
$name = iconv('utf-8', 'gb2312', "upload/" . $file["name"]);
move_uploaded_file($file['tmp_name'], $name);
move_uploaded_file($file['tmp_name'], "upload/" . $file["name"]);
echo $file["name"];
die();

  html:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>Title</title>
<script src="http://cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>
<input type="file" id="fileS" name="file" accept="image/*">
<button>提交</button>
</body>
<script>
$(() => {
$("button").click(() => {
let formdata = new FormData();
formdata.append('file', $("#fileS")[0].files[0]);
$.ajax({
url: "./file_updata.php",
type: "post",
data: formdata,
contentType: false,
processData: false,
mimeType: "multipart/form-data",
success: function (data) {
console.log(data)
},
error: function (error) {
console.log("error", error)
}
}
)
})
})
</script>
</html>

  

ajax如何上传文件的更多相关文章

  1. Ajax方式上传文件

    用到两个对象 第一个对象:FormData 第二个对象:XMLHttpRequest 目前新版的Firefox 与 Chrome 等支持HTML5的浏览器完美的支持这两个对象,但IE9尚未支持 For ...

  2. koa2:通过Ajax方式上传文件,使用FormData进行Ajax请求

    koa2通过表单上传的网上很多,但通过Ajax方式上传文件,使用FormData进行Ajax请求,不好找. 参考了这个用base64上传图片的例子.https://github.com/Yuki-Mi ...

  3. (23)ajax实现上传文件的功能

    form表单上传文件 urls.py from django.conf.urls import urlfrom django.contrib import adminfrom app01 import ...

  4. SSM框架下,使用ajax请求上传文件(doc\docx\excel\图片等)

    1.准备工作 1.1.添加上传必要jar包 <dependency> <groupId>commons-io</groupId> <artifactId> ...

  5. ajax异步上传文件和表单同步上传文件 的区别

    1. 用表单上传文件(以照片为例)-同步上传 html部分代码:这里请求地址index.php <!DOCTYPE html> <html lang="en"&g ...

  6. ajax如何上传文件(整理)

    ajax如何上传文件(整理) 一.总结 一句话总结:用FormData,FormData+ajax=异步上传二进制文件 <form enctype="multipart/form-da ...

  7. django中通过文件和Ajax来上传文件

    一.通过form表单来上传文件 1.在html模板中 <form action="/index/" method="post" enctype=" ...

  8. 基于Flask开发网站 -- 前端Ajax异步上传文件到后台

    大家好,我是辰哥~ 辰哥最近利用空闲时间在写一个在线可视化平台,过程中也觉得一些技术还是比较有意思的,所以就以模块化的形式分享出来.如:从网页界面(前端)上传文件到服务器(后端). 放一下该模块的界面 ...

  9. ajax实现上传文件

      1.html部分 <input style="width: 280px" type="file" name="upLoadProjectPl ...

  10. 通过Ajax方式上传文件,使用FormData进行Ajax请求

    通过传统的form表单提交的方式上传文件: <form id= "uploadForm" action= "http://localhost:8080/cfJAX_ ...

随机推荐

  1. Linux进阶:让效率翻倍的Bash技巧(一)

    http://blog.tpircsboy.com/tech/bash-skills-part1/

  2. PHP 之超级全局变量

    参考菜鸟教程,并经过自己亲手实验,记录PHP的几个超级全局变量 所谓超级全局变量 ,你可以理解为在一个脚本里面的全部代码里面都可以使用的变量. $GLOBALS $GLOBALS 是 php 的一个超 ...

  3. Bit operator: Left shift and Right shift (Signed or unsigned? )

    No matter left shift or right shift, the result's sign should always be the same as its left operand ...

  4. DataGridView使用技巧九:DataGridView的右键菜单(ContextMenuStrip)

    DataGridView,DataGridViewColumn,DataGridViewRow,DataGridViewCell有ContextMenuStrip属性.可以通过设置ContextMen ...

  5. wex5中集成的mysql数据库 打开时一闪而过 报错

    在进程中kill mysql.exe 重新启动即可

  6. [转载] PHP开发必看 编程十大好习惯

    适当抽象 但是在抽象的时候,要避免不合理的抽象,有时也可能造成过渡设计,现在只需要一种螺丝刀,但你却把更多类型的螺丝刀都做出来了(而且还是瑞士军刀的样子..): 一致性 团队开发中,可能每个人的编程风 ...

  7. e647. 处理鼠标移动事件

    component.addMouseMotionListener(new MyMouseMotionListener()); public class MyMouseMotionListener ex ...

  8. e640. 使一个组件可拖动

    This example demonstrates the code needed to make a component draggable. The object being transferre ...

  9. PHP curl_setopt函数用法介绍上篇

    最近,学习与实践了php中curl的知识点.在此做个初步的总结: 先看看对于它的基本介绍: curl_setopt函数是php中一个重要的函数,它可以模仿用户的一些行为,如模仿用户登录,注册等等一些用 ...

  10. AOP技术应用和研究--AOP简单应用

    为了更好的理解AOP实践和体现AOP的优势.我们始终将OOP和AOP的比較贯穿到下文中.并在终于总结出AOP与OOP相比所拥有的长处,AOP的缺点以及AOP一般的使用场景. 1.1 问题空间到解空间的 ...