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 ...
随机推荐
- Android 通过 Wifi 调试 Debug (Android Studio)
参考资料: http://www.cnblogs.com/sunzhenxing19860608/archive/2011/07/14/2106492.html 前提: Android 手机 和 PC ...
- 突破软件试用期的"土方法"
机器上有个试用版的vs2008. 想能正常用,又木有去搜序列号.于是用python纠结了这么一段代码: import time import subprocess import os timeNow ...
- 使用复合索引代替单键索引,来避免单键有null值的情况
查看原表: SQL> select count(*) from t1; COUNT(*) ---------- 3229088 SQL> select count(*) from t1 w ...
- grub paramiter & menu.list
在Linux中,给kernel传递参数以控制其行为总共有三种方法: 1.build kernel之时的各个configuration选项. 2.当kernel启动之时,可以参数在kernel被GRUB ...
- JS中对this的理解
// this: 指的是调用 当前 方法(函数)的那个对象 <script> function fn1(){ this } 情况1:fn1() //这里t ...
- 在SQLite Expert上用日期类型字段作为条件查询时注意日期的格式化
经验之谈: 情况一:没有查询结果 and R_CheckInTime > '2015-7-12 18:47:00' and R_CheckInTime < '2015-7-18 18:48 ...
- struts2实现文件上传、多文件上传和文件下载
总结的两个问题,就是struts2上传下载的时候对属性名配置要求非常严格: 第一:上传的时候 private File file; private String fileContentType; pr ...
- .NET中通過OUTLOOK發送附件內容
最近碰到一個發送郵件附件的問題,隨便幾下來,方便以後學習. string[] files = System.IO.Directory.GetFiles(@"~/UploadData" ...
- atomic vs. nonatomic
Declaring a property atomic makes compiler generate additional code that prevents concurrent access ...
- mac攻略(五) -- 使用brew配置php7开发环境(mac+php+apache+mysql+redis)
前面介绍过基本的配置,后来我又从网上查找了很多资料,经过不断的摸索,下面做了一个总结,希望能对大家提供些许帮助(Mac版本是sierra) 一.mac系统会自带git,而我们要做的是自己安装git ...