jquery批量上傳php
批量上傳圖片就是循環的單張上傳~~,思路和單張上傳差不多的~
② 【高分懸賞】jquery ajax批量添加數據 通過PHP寫進MYSQL。。。
這個貌似你只需要一次ajax請求吧。
參數:發消息的人的ID,消息內容,接受消息的好友(全部就為空,部分就[1,5,9,11])
其他的就伺服器程序處理了。
你這樣要請求個無數次,有什麼意義呢?純粹是自己在給伺服器增加壓力
③ php使用jquery無刷新上傳,可預覽,刪圖
可以批量上傳圖片什麼的以及可以預覽的都是用flash來實現的
js最多隻能單張上傳,還不能預覽。
④ 我需要一個js或者jquery能批量上傳圖片+預覽的功能。急~~~急~~~急~~
WebUploader項目,符合你的要求。
//文件上傳過程中創建進度條實時顯示。
uploader.on('uploadProgress',function(file,percentage){
var$li=$('#'+file.id),
$percent=$li.find('.progressspan');
//避免重復創建
if(!$percent.length){
$percent=$('<pclass="progress"><span></span></p>')
.appendTo($li)
.find('span');
}
$percent.css('width',percentage*100+'%');
});
//文件上傳成功,給item添加成功class,用樣式標記上傳成功。
uploader.on('uploadSuccess',function(file){
$('#'+file.id).addClass('upload-state-done');
});
//文件上傳失敗,顯示上傳出錯。
uploader.on('uploadError',function(file){
var$li=$('#'+file.id),
$error=$li.find('div.error');
//避免重復創建
if(!$error.length){
$error=$('<divclass="error"></div>').appendTo($li);
}
$error.text('上傳失敗');
});
//完成上傳完了,成功或者失敗,先刪除進度條。
uploader.on('uploadComplete',function(file){
$('#'+file.id).find('.progress').remove();
});
更多細節,請查看js源碼。
⑤ uploadify批量上傳
創建了一個web project
commons-fileupload-1.2.2.jar
commons-io-2.0.1.jar
首先把這兩個jar文件引入了path
然後創建了一個servlet
Upload.java(用的MyEclipse自動配置了web.xml部署描述符)
[java] view plain
//Upload.java  
package com.uploadify.servlet;  
  
import java.io.File;  
import java.io.IOException;  
import java.util.Iterator;  
import java.util.List;  
  
import javax.servlet.ServletException;  
import javax.servlet.http.HttpServlet;  
import javax.servlet.http.HttpServletRequest;  
import javax.servlet.http.HttpServletResponse;  
  
import org.apache.commons.fileupload.FileItem;  
import org.apache.commons.fileupload.FileUploadException;  
import org.apache.commons.fileupload.disk.DiskFileItemFactory;  
import org.apache.commons.fileupload.servlet.ServletFileUpload;  
  
import com.uploadify.utils.IPTimeStamp;  
  
public class Upload extends HttpServlet {  
  
    public void doGet(HttpServletRequest request, HttpServletResponse response)  
            throws ServletException, IOException {  
        this.doPost(request, response);  
    }  
  
    public void doPost(HttpServletRequest request, HttpServletResponse response)  
            throws ServletException, IOException {  
  
        String savePath = this.getServletConfig().getServletContext()  
                .getRealPath("");  
        // 得到項目的工作目錄  
        savePath = savePath + "/uploads/";  
        File f1 = new File(savePath);  
        // 如果沒有的話就創建目錄  
        if (!f1.exists()) {  
            f1.mkdirs();  
        }  
        DiskFileItemFactory fac = new DiskFileItemFactory();  
        ServletFileUpload upload = new ServletFileUpload(fac);  
        upload.setHeaderEncoding("utf-8");  
        List fileList = null;  
        try {  
            fileList = upload.parseRequest(request);  
        } catch (FileUploadException ex) {  
            return;  
        }  
        Iterator<FileItem> it = fileList.iterator();  
        String name = "";  
        String extName = "";  
        while (it.hasNext()) {  
            FileItem item = it.next();  
            if (!item.isFormField()) {  
  
                // 解析文件  
                name = item.getName();  
                long size = item.getSize();  
                String type = item.getContentType();  
                if (name == null || name.trim().equals("")) {  
                    continue;  
                }  
                // 得到文件的擴展名  
                if (name.lastIndexOf(".") >= 0) {  
                    extName = name.substring(name.lastIndexOf("."));  
                }  
                File file = null;  
                do {  
                    // 利用客戶端IP+時間+三位隨機數字生成非重復文件名:  
                    name = new IPTimeStamp().getIPTimeStampRandom();  
                    file = new File(savePath + name + extName);  
                } while (file.exists());  
                File saveFile = new File(savePath + name + extName);  
                try {  
                    item.write(saveFile);  
                } catch (Exception e) {  
                    e.printStackTrace();  
                }  
            }  
        }  
        response.getWriter().print(name + extName);  
    }  
  
}  
生成文件名字的Utils類,可以清楚的記錄名字,然後對上傳的文件進行處理,並且防止文件名字重復
[java] view plain
//PTimeStamp.java  
package com.uploadify.utils;  
  
import java.net.InetAddress;  
import java.net.UnknownHostException;  
import java.text.SimpleDateFormat;  
import java.util.Date;  
import java.util.Random;  
  
public class IPTimeStamp {  
    private String ip;  
    private Date date;  
    private SimpleDateFormat format;  
  
    public IPTimeStamp() {  
        try {  
            ip = InetAddress.getLocalHost().getHostAddress();  
        } catch (UnknownHostException e) {  
            // TODO Auto-generated catch block  
            e.printStackTrace();  
        }  
    }  
  
    public String getTimeStamp() {  
        format = new SimpleDateFormat("yyyyMMddHHmmssSSS");  
        return format.format(new Date());  
    }  
  
    public String addZero(String str, int len) {  
        StringBuffer sb = new StringBuffer();  
        sb.append(str);  
        while (sb.length() < len) {  
            sb.insert(0, "0");  
        }  
        return sb.toString();  
    }  
  
    public String getIPTimeStampRandom() {  
        StringBuffer sb = new StringBuffer();  
        String[] ips = this.ip.split("\\.");  
  
        for (int j = 0; j < ips.length; j++) {  
            // System.out.println(ips[j]);  
            sb.append(this.addZero(ips[j], 3));  
        }  
        sb.append(this.getTimeStamp());  
        Random rod = new Random();  
        for (int i = 0; i < 3; i++) {  
            sb.append(rod.nextInt(10));  
        }  
        return sb.toString();  
    }  
}  
部署描述符
[html] view plain
<!--web.xml-->  
<?xml version="1.0" encoding="UTF-8"?>  
<web-app version="2.4"   
    xmlns="http://java.sun.com/xml/ns/j2ee"   
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">  
  <servlet>  
    <servlet-name>Upload</servlet-name>  
    <servlet-class>com.uploadify.servlet.Upload</servlet-class>  
  </servlet>  
  
  <servlet-mapping>  
    <servlet-name>Upload</servlet-name>  
    <url-pattern>/Upload</url-pattern>  
  </servlet-mapping>  
  <welcome-file-list>  
    <welcome-file>index.jsp</welcome-file>  
  </welcome-file-list>  
</web-app>  
在WebROOT下面創建folder->js
放入解壓包裡面的
jquery.uploadify.v2.1.4.js
jquery.uploadify.v2.1.4.min.js
jquery-1.4.2.min.js
swfobject.js
css->
uploadify.css
images->
cancel.png
[html] view plain
<!--index.jsp-->  
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  
<%  
    String path = request.getContextPath();  
    String basePath = request.getScheme() + "://"  
            + request.getServerName() + ":" + request.getServerPort()  
            + path + "/";  
%>  
  
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
<html>  
    <head>  
        <base href="<%=basePath%>">  
  
        <title>My JSP 'index.jsp' starting page</title>  
        <meta http-equiv="pragma" content="no-cache">  
        <meta http-equiv="cache-control" content="no-cache">  
        <meta http-equiv="expires" content="0">  
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
        <meta http-equiv="description" content="This is my page">  
        <link href="css/uploadify.css" rel="stylesheet" type="text/css" />  
        <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>  
        <script type="text/javascript" src="js/swfobject.js"></script>  
        <script type="text/javascript" src="js/jquery.uploadify.v2.1.4.js"></script>  
        <script type="text/javascript">  
        $(document).ready(function() {  
            $("#uploadify").uploadify({  
                'uploader'       : 'uploadify.swf',  
                'script'         : 'Upload',  
                'cancelImg'      : 'images/cancel.png',  
                'folder'         : 'uploads',  
                'queueID'        : 'fileQueue',  
                'auto'           : false,  
                'multi'          : true,  
                'simUploadLimit' : 2,  
                'buttonText'     : 'BROWSE'  
            });  
        });  
        </script>  
    </head>  
  
    <body>  
        <div id="fileQueue"></div>  
        <input type="file" name="uploadify" id="uploadify" />  
        <p>  
            <a href="javascript:jQuery('#uploadify').uploadifyUpload()">開始上傳</a>   
            <a href="javascript:jQuery('#uploadify').uploadifyClearQueue()">取消所有上傳</a>  
        </p>  
    </body>  
</html>
⑥ jquery 上傳文件插件uploadify jsp版本
寫一個servlet,看這里
http://www.javaeye.com/topic/376101
⑦ jquery怎麼實現多文件上傳 php
jquery有個插件叫uploadify
http://www.uploadify.com/
$(function(){
	$("#file_upload_1").uploadify({
		height:30,
		swf:'/uploadify/uploadify.swf',
		uploader:'/uploadify/uploadify.php',
		width:120
	});
});
⑧ javascript(jquery)怎麼傳變數給php
可以使用ajax來實現
$.ajax({
type:'post',
url:"你的php地址+參數",
success:function(data){
php返回的結果就是data
}
});請將jquery引入到網頁,不然無法使用。
還有什麼問題歡迎追問。
