ajax 异步插入图片到数据库(单图上传)
其实也没啥 如图:

点击按钮选择图片,选择完成后 无需点击确定 ,自动上传到服务器指定文件夹 然后插入到数据库中。
下面来看看这要代码
index.php
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>UploadiFive Test</title>
<script src="//cdn.bootcss.com/jquery/2.0.0/jquery.min.js" type="text/javascript"></script>
<script src="jquery.uploadify.min.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="uploadify.css">
<style type="text/css">
body {
font: 13px Arial, Helvetica, Sans-serif;
}
</style>
</head> <body>
<h1>Uploadify Demo</h1>
<form action="uploadify.php" method="post">
<div id="queue"></div>
<input id="file_upload" name="tupian" type="file" multiple="true">
<!-- <input type="submit" value="上传"/>-->
</form> <script type="text/javascript">
<?php $timestamp = time();?>
$(function() {
$('#file_upload').uploadify({
'formData' : {
'timestamp' : '<?php echo $timestamp;?>',
'token' : '<?php echo md5('unique_salt' . $timestamp);?>'
},
'swf' : 'uploadify.swf',
'uploader' : 'uploadify.php'
});
});
</script>
</body>
</html> 上传页面的 uploadifty.php
<?php
include("conn.php");
/*
Uploadify
Copyright (c) 2012 Reactive Apps, Ronnie Garcia
Released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
*/
error_reporting(0);
// Define a destination
$targetFolder = '/DoExercise/uploadify/uplaods'; // Relative to the root $verifyToken = md5('unique_salt' . $_POST['timestamp']); if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name']; // Validate the file type
$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']); if (in_array($fileParts['extension'],$fileTypes)) {
move_uploaded_file($tempFile,$targetFile);
echo '1';
} else {
echo 'Invalid file type.';
}
$tupian=$_FILES['Filedata']['name'];
$sql="insert into uploadify(tupian) values('$tupian')";
$query=mysql_query($sql);
if($query>0){
echo "<script>alert('上传成功')</script>";
}else{ echo"<script>alert('上传失败')</script>";
} }
?>
,$fileTypes)) { move_uploaded_file($tempFile,$targetFile); echo '1'; } else { echo 'Invalid file type.'; } $tupian=$_FILES['Filedata']['name']; $sql="insert into uploadify(tupian) values('$tupian')"; $query=mysql_query($sql); if($query>0){ echo "<script>alert('上传成功')</script>"; }else{ echo"<script>alert('上传失败')</script>"; }}?>
主要就这些玩意 也没啥 东西 需要文件的 找我来哈 认准大白驴。
ajax 异步插入图片到数据库(单图上传)的更多相关文章
- ajax 异步插入图片到数据库(多图上传)
额 大概就这么个样子...截个图 点浏览 选择几张图片 选择完了 确定一下 然后插入数据库 同时在页面中显示插入的图片,代码 也没啥.看下 index.php <html><hea ...
- js formData图片上传(单图上传、多图上传)后台java
单图上传 <div class="imgUp"> <label>头像单图</label> <input type=&quo ...
- java插入图片到数据库(可以批量)
package sundun.zfpt.gg.web; import java.io.File; import java.io.FileInputStream; import java.sql.Con ...
- 服务器文档下载zip格式 SQL Server SQL分页查询 C#过滤html标签 EF 延时加载与死锁 在JS方法中返回多个值的三种方法(转载) IEnumerable,ICollection,IList接口问题 不吹不擂,你想要的Python面试都在这里了【315+道题】 基于mvc三层架构和ajax技术实现最简单的文件上传 事件管理
服务器文档下载zip格式 刚好这次项目中遇到了这个东西,就来弄一下,挺简单的,但是前台调用的时候弄错了,浪费了大半天的时间,本人也是菜鸟一枚.开始吧.(MVC的) @using Rattan.Co ...
- UEditor单图上传跨域问题解决方案
UEditor UEditor是百度团队提供的富文本编辑器 git地址为:https://github.com/fex-team/ueditor 在最近的项目中使用了该插件作为项目的富文本编辑器 由于 ...
- Laravel5多图上传和Laravel5单图上传的功能实现
Laravel5文件上传默认只能上传一张图片,但是有的时候我们需要一次性上传多图就不行了,我在网上看了很多关于laravel5图片上传的文章,很多都只是介绍laravel5单图上传,多图片上传介绍少之 ...
- Spring Boot MVC 单张图片和多张图片上传 和通用文件下载
@Autowired private ServerConfig serverConfig; /** * 通用下载请求 * * @param fileName 文件名称 * @param delete ...
- #添加图片,最多只能上传9张.md
#添加图片,最多只能上传9张.md 前端页面: ```javascript <form id="imgForm" enctype="multipart/form-d ...
- node多图或者单图上传
<form id="form" enctype="multipart/form-data"> <input type="text&q ...
随机推荐
- ORA-25153: Temporary Tablespace is Empty
在一测试环境做测试的时候发生以下错误: SQL> exec dbms_stats.gather_table_stats(ownname=>'SYS',tabname=>'TT',me ...
- android IntentFilter 使用之 data过滤
1 Intent分为两大类,显式和隐式. 显式事件,就是指通过 component Name 属性,明确指定了目标组件的事件. 比如我们新建一个Intent,指名道姓的说,此事件用于启动名为" ...
- session跟cookies区别
Session和Cookie的使用总结: Session和cookie都是asp.Net中的内置对象,至于他们有什么区别,在这里就不在多说,现在来说说一些比较实用点的东西: 我们知道网站都有一个后台管 ...
- 关于在archlinux中安装virtualbox
之前安装的时候具体忘记了,现在重新整理一下安装的过程: 1. 安装virtualbox sudo pacman -S virtualbox 安装的过程中因依赖,需要安装提供host模块的包,这里我们安 ...
- 配置本地光盘为yum源
挂载cd-rom mount /dev/cdrom /mnt http://javaarm.com/faces/display.xhtml?tid=3520 关闭selinux vi /etc/sys ...
- Android之使用Volley框架在ListView中加载大量图片
1.listview 中的条目要用 Volley 中的 NetworkImageView,如果直接用ImageView也可以,但是要在getView方法中使用url地址设置为imageView的tag ...
- js基础的知识整理
一.操作样式: .style 操作行间样式 .className 修改class 二.操作属性 1. . 更简单,操作已有的属性 2. [] 更灵活,点能做的,方括号都能做.方括号中放的是字符串 ...
- noi 8462 大盗阿福
题目链接:http://noi.openjudge.cn/ch0206/8462/ 相邻的两个不能同时取, d[i] = max(d[i-1],d[i-2]+a[i]); http://paste.u ...
- R----tidyr包介绍学习
tidyr包:reshape2的替代者,功能更纯粹 tidyr包的应用 tidyr主要提供了一个类似Excel中数据透视表(pivot table)的功能;gather和spread函数将数据在长格式 ...
- JavaScript格式化时间
最近最练习遇到一个问题,就是从数据库中获取时间,利用EasyUI界面来显示时间类型的生日,发现它是按照毫秒来计算的long型数据,在界面显示并不能到达到一目了然,这里可以用两种方法来解决这个问题 在d ...