JavaScript Uploadify文件上传实例

前言

java+javascript,没用上数据库,做了一个简简单单的jsp上传小功能,就是记录一下,对于这个小项目有什么建议,欢迎指出不足之处 (-_+)

PS:从我的包名看得出,我用过很多前辈们的代码,基本上都是东凑西拼,各个部分代码的出处就不一一列出了,能看就行!

运行环境:

Java EE + Tomcat 7.0

项目结构
( Dynamic Web Project )

src各部分代码

1. com.bijian.study.Upload.java

package com.bijian.study;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
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.test.util.FileUtil;

@SuppressWarnings("serial")
public class Upload extends HttpServlet {

  private final String SEP = File.separator;
  private FileUtil fUtil = new FileUtil();

  @SuppressWarnings("unchecked")
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    String savePath = this.getServletConfig().getServletContext()
        .getRealPath("");
    savePath = savePath + "/uploads/";

    File f1 = new File(savePath);
    System.out.println(savePath);
    if (!f1.exists()) {
      f1.mkdirs();
    }
    DiskFileItemFactory fac = new DiskFileItemFactory();
    ServletFileUpload upload = new ServletFileUpload(fac);
    upload.setHeaderEncoding("utf-8");

    String package_path = request.getParameter("save_path");
    String remark = request.getParameter("remark");

    List fileList = null;
    try {
      fileList = upload.parseRequest(request);
    } catch (FileUploadException ex) {
      return;
    }
    Iterator<FileItem> it = fileList.iterator();
    String name = "";
    String extName = "";
    String sysDate = "";
    String fileFrom = "";
    while (it.hasNext()) {
      FileItem item = it.next();
      if (!item.isFormField()) {
        long size = item.getSize();
        String type = item.getContentType();
        name = item.getName();
        if (name == null || name.trim().equals("")) {
          continue;
        }
        if (name.lastIndexOf(".") >= 0) {
          extName = name.substring(name.lastIndexOf("."));
        }
        File file = null;
        do {
          file = new File(savePath + name + extName);
        } while (file.exists());
        File saveFile = new File(savePath + name);
        fileFrom = saveFile.getAbsolutePath();
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat(
            "yyyy/MM/dd HH:mm:ss");
        sysDate = dateFormat.format(now);
        try {
          item.write(saveFile);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
    remark = ChangeDeocode(remark);
    package_path = ChangeDeocode(package_path);

    String keep_path = "C:" +SEP+ package_path+SEP+name;
    String save_path = "C:" +SEP+ package_path;
    if(!fUtil.isFileExist(save_path)){
      fUtil.mkDir("C:" +SEP+ package_path);
    }

    fUtil.copyFile(fileFrom, keep_path);
    if(fUtil.isFileExist(keep_path)){
      fUtil.appendMethod(name + "|" + sysDate + "|" + remark+"|"+save_path);
    }
    response.getWriter().print(name + "\\" + sysDate + "\\" + remark);
  }

  public String ChangeDeocode(final String dataStr) {
    String ToDeocode = "";
    if (dataStr.contains("%")) {
      char[] charArray = dataStr.toCharArray();
      int ToChangeIndex = 0;

      for (int i = 0; i < charArray.length; i++) {
        if (i <= ToChangeIndex && i != 0) {
          continue;
        } else {
          if (charArray[i] == '%' && charArray[i + 1] == 'u'
              && i + 5 < charArray.length) {
            char[] tempArray = new char[] { charArray[i],
                charArray[i + 1], charArray[i + 2],
                charArray[i + 3], charArray[i + 4],
                charArray[i + 5] };
            ToDeocode += decodeUnicode(String.valueOf(tempArray));
            ToChangeIndex = i + 5;
          } else {
            ToDeocode += charArray[i];
            continue;
          }
        }
      }
    }
    return ToDeocode;
  }

  public String decodeUnicode(final String dataStr) {
    int start = 0;
    int end = 0;
    final StringBuffer buffer = new StringBuffer();
    while (start > -1) {
      end = dataStr.indexOf("\\u", start + 2);
      String charStr = "";
      if (end == -1) {
        charStr = dataStr.substring(start + 2, dataStr.length());
      } else {
        charStr = dataStr.substring(start + 2, end);
      }
      char letter = (char) Integer.parseInt(charStr, 16); // 16进制parse整形字符串。
      buffer.append(new Character(letter).toString());
      start = end;
    }
    return buffer.toString();
  }
}

2. com.test.tag.MyIteratorTag.java

package com.test.tag;

import java.io.File;
import java.io.IOException;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

public class MyIteratorTag extends TagSupport {

  private final String SEP = File.separator;
  private List<String[]> files = null;
  private List<String[]> data = null;
  private int columnSize = 0;

  @Override
  public int doStartTag() throws JspException {
    // TODO Auto-generated method stub

    JspWriter out = this.pageContext.getOut();
    StringBuffer sf = new StringBuffer();

    sf.append("<table style='width:1000;' border='1' cellspacing='0' cellpadding='10'>");
    sf.append("<tr><td>");
    sf.append("<table style='width:200;' border='0' cellspacing='0'>");   

    if (this.data == null || this.data.isEmpty()) {
      sf.append(" <tr>");
      sf.append("  <td>");
      sf.append("  <B> No Valid Data List is NULL </B> ");
      sf.append("  </td>");
      sf.append(" </tr>");
    } else {
      for (int i = 0; i < data.size(); i++) {
        String[] trs = data.get(i);
        sf.append("<tr>");
        for (int j = 0; j < trs.length; j++) {
          switch (j) {
          case 0:
            sf.append("<td>");
            sf.append("<a href='javascript:ReStartJSP("+i+")'>"+trs[j]+"</a>");
            sf.append("<input type='hidden' value='"+trs[j]+"' id='hidden_"+i+"'/>");
            sf.append("</td>");
            break;
          case 1:
            sf.append("<td>");
            sf.append("\t"+trs[j]);
            sf.append("</td>");
            break;
          case 2:
            sf.append("<td>");
            sf.append("張");
            sf.append("</td>");
            break;
          case 3:
            sf.append("<td>");
            sf.append("<input type='image' value='"+i+"' src='img"+SEP+"exchange_icon.png' onclick='showDIV(this)'/>");
            sf.append("</td>");
            break;

          default:
            sf.append("<td>");
            sf.append("<input type='image' value='"+trs[0]+"' src='img"+SEP+"exchange_icon.png' onclick='showDIV(this)'/>");
            sf.append("</td>");
            break;
          }
        }
        sf.append("</tr>");
      }
    }
    sf.append("</table>");
    sf.append("</td>");
    sf.append("<td>");
    sf.append("<table style='width:600;' border='0' cellspacing='0'>");

    if(this.files != null && !this.files.isEmpty()){
      for (int i = 0; i < files.size(); i++) {
        String[] trs = files.get(i);
        sf.append("<tr><u>");
        for (int j = 0; j < trs.length; j++) {
          sf.append("<td>");
          sf.append("\t"+trs[j]);
          sf.append("</td>");
        }
        sf.append("<td>");
        sf.append("<input type='image' value='"+trs[1]+"' src='img/uploadify-cancel.png' onclick='deleteFile(this.value)'/>");
//       System.out.println("trs["+i+"]"+trs[i]);
        sf.append("</td>");
        sf.append("</u></tr>");
      }
    }

    sf.append("</table>");
    sf.append("</td></tr>");
    sf.append("</table>");

    try {
      out.print(sf.toString());
    } catch (IOException e) {
      e.printStackTrace();
      throw new JspException(e.getMessage());
    }
    return super.doEndTag();
  }

  public List<String[]> getfiles() {
    return files;
  }

  public void setfiles(List<String[]> files) {
    this.files = files;
  }

  public List<String[]> getData() {
    return data;
  }

  public void setData(List<String[]> data) {
    this.data = data;
  }

  public int getColumnSize() {
    return columnSize;
  }

  public void setColumnSize(int columnSize) {
    this.columnSize = columnSize;
  }

}

3. com.test.util.FileStringUtil.java

package com.test.util;

import java.util.HashMap;
import java.util.Map;

public class FileStringUtil {

  public Map<String, String> getFileDetails(String fileString){
    Map<String, String> detailMap = new HashMap<>();
    String[] splitStr = fileString.split("\\|");
    for (int i = 0; i < splitStr.length; i++) {
      detailMap.put("fileDetail"+i, splitStr[i]);
    }
    return detailMap;
  }
}

4. com.test.util.FileUtil.java

package com.test.util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;

import org.apache.catalina.authenticator.SavedRequest;

public class FileUtil {

  private final String SEP = File.separator;
  int count = 0;

  public static String [] getFileName(String path){
    File file = new File(path);
    String [] fileName = file.list();
    return fileName;
  }

  public boolean isFileExist(String path) {
    try {
      File file = new File(path);
      return file.exists();
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    return false;
  }

  public boolean mkDir(String path) {
    File dir = new File(path);
    boolean res = dir.mkdirs();
    return res;
  }

  public List<String> readTxtFile(String filePath) {
    List<String> resultList = new ArrayList<>();
    try {
      String encoding = "UTF-8";
      File file = new File(filePath);
      if (file.isFile() && file.exists()) { // 判断文件是否存在
        InputStreamReader read = new InputStreamReader(new FileInputStream(file), encoding);// 考虑到编码格式
        BufferedReader bufferedReader = new BufferedReader(read);
        String lineTxt = null;
        while ((lineTxt = bufferedReader.readLine()) != null) {
          if(lineTxt.length() < 2){
            continue;
          }else {
            resultList.add(lineTxt);
          }
        }
        read.close();
      } else {
        System.out.println("找不到指定的文件");
      }
    } catch (Exception e) {
      System.out.println("读取文件内容出错");
      e.printStackTrace();
    }
    return resultList;
  }

  public List<String> readTxtFileByPath(String filePath,String Path) {
    String savePath = "c:\\"+Path;
    List<String> resultList = new ArrayList<>();
    try {
      String encoding = "UTF-8";
      File file = new File(filePath);
      if (file.isFile() && file.exists()) { // 判断文件是否存在
        InputStreamReader read = new InputStreamReader(new FileInputStream(file), encoding);// 考虑到编码格式
        BufferedReader bufferedReader = new BufferedReader(read);
        String lineTxt = null;
        int lineNumber = 0;
        while ((lineTxt = bufferedReader.readLine()) != null) {
          lineNumber++;
          System.out.println("lineNumber "+lineNumber);
          if(lineTxt.length() < 2){
            continue;
          }else {
            String lastRead = lineTxt.substring(lineTxt.lastIndexOf("|")+1,lineTxt.length());
            String fristRead = lineTxt.substring(0,lineTxt.indexOf("|"));
            if(lastRead.toUpperCase().equals(savePath.toUpperCase())){

              File savePathFile = new File(savePath);
              File[] files = savePathFile.listFiles();

              if(files.length == 0){//當文件夾所有文件不存在時
                lineTxt = "";
                System.out.println("none file of "+savePath);
              }else {
                boolean fileDelete = true;
                for (int i = 0; i < files.length; i++) {
                  System.out.println("files" + files[i].getName());
                  System.out.println("fristRead"+fristRead);
                  if(fristRead.equals(files[i].getName())){
                    //當文件列表中存在一則記錄文件名與列表文件名匹配時,證明文件沒有被刪除
                    fileDelete = false;
                  }
                }
                if (fileDelete) {
                  //文件是否被刪除,是:刪除該條記錄;否:記錄應當存留
                  deleteLineText(lineNumber);
                }else {
                  resultList.add(lineTxt);
                }
              }
            }
          }

        }
        read.close();
      } else {
        System.out.println("找不到指定的文件");
      }
    } catch (Exception e) {
      System.out.println("读取文件内容出错");
      e.printStackTrace();
    }
    return resultList;
  }

  public void deleteLineText(int lineNum){
//   BufferedReader br;
    try {
//     br = new  BufferedReader(new FileReader("c:/a.txt "));
      BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("c:\\a.txt"),"UTF-8"));
      StringBuffer sb=new StringBuffer(4096);
      String temp=null;
      int  line=0;

      while((temp=br.readLine())!=null){
          line++;
          if(line==lineNum)
            continue;
          sb.append(temp).append("\r\n");
//         sb.append(new String(temp.getBytes("Unicode"), "UTF-8")).append( "\r\n ");
      }
      br.close();
      OutputStreamWriter write = new OutputStreamWriter(new FileOutputStream("c:/a.txt "),"UTF-8");
      BufferedWriter writer=new BufferedWriter(write);
//     BufferedWriter  bw=new  BufferedWriter(new FileWriter( "c:/a.txt "));
      writer.write(sb.toString());
      writer.close();
    } catch (FileNotFoundException e) {
      System.out.println(e.toString());
      e.printStackTrace();
    } catch (IOException e) {
      System.out.println(e.toString());
      e.printStackTrace();
    }

  }

  public void writeTxtFile(File file, String fileContent)
  {
    try
    {
      OutputStreamWriter write = new OutputStreamWriter(new FileOutputStream(file),"UTF-8");
      BufferedWriter writer=new BufferedWriter(write);
      writer.write(fileContent);
      writer.close();
    } catch (Exception e)
    {
      e.printStackTrace();
    }
  }

  public int[] getAllFileSize(String[] filePath){
    int[] fileSizeArray = new int[filePath.length];
    for (int i = 0; i < filePath.length; i++) {
      if(!isFileExist("c:\\"+filePath[i])){
        mkDir("c:\\"+filePath[i]);
      }
      File file = new File("c:\\"+filePath[i]);
      File[] files = file.listFiles();
      fileSizeArray[i] = files.length;
    }
    return fileSizeArray;

  }

  public String deleteFile(){
    String result = "";
    if(count == 0){
      System.out.println("0");
      result = "0";
    }else {
      System.out.println("deleteFile");
      result = "deleteFile";
    }
    count++;
    return result;
  }

  public void appendMethod(String content) {

    try {
      File file = new File("C:\\a.txt");
      if (!file.exists()){
         file.createNewFile();
        writeTxtFile(file,content);
      }else {
       Writer out = new BufferedWriter( new OutputStreamWriter(new FileOutputStream("C:\\a.txt",true),"UTF-8"));
       out.write("\r\n"+content);
       out.close();
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

  public static boolean copyFile(String fromFile, String toFile) {
    try {
      InputStream fosfrom = new FileInputStream(fromFile);
      OutputStream fosto = new FileOutputStream(toFile);
      byte bt[] = new byte[4096];
      int c;
      while ((c = fosfrom.read(bt)) > 0) {
        fosto.write(bt, 0, c);
      }
      fosfrom.close();
      fosto.close();
      bt = null;
      return true;

    } catch (Exception ex) {
      ex.printStackTrace();
      return false;
    }
  }
}

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.bijian.study.Upload</servlet-class>
 </servlet> 

 <servlet-mapping>
  <servlet-name>upload</servlet-name>
  <url-pattern>/servlet/Upload</url-pattern>
 </servlet-mapping> 

 <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
 </welcome-file-list> 

<jsp-config>
<taglib>
  <!-- 对应的uri jsp中声明的需要用到 -->
 <taglib-uri>my-taglib</taglib-uri>
 <!-- 对应标签描述文件所在的位置 -->
 <taglib-location>/WEB-INF/my-taglib.tld</taglib-location>
 </taglib>
</jsp-config>
</web-app>

index.jsp

<%@page import="org.apache.tomcat.jni.File"%>
<%@ page language="java" contentType="text/html; charset=utf-8" import="java.util.*" import="com.test.util.*"%>
<%@ taglib uri="my-taglib" prefix="myTag"%>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://"
      + request.getServerName() + ":" + request.getServerPort()
      + path + "/"; 

  int SHOW_CONTROL = 0;

  final String RECORED_PATH = "c:\\a.txt";
  String getParameter = request.getParameter("num");
  if(getParameter !=null){
    System.out.println("getParameter "+getParameter);
    SHOW_CONTROL = Integer.parseInt(getParameter);
  }else{
    SHOW_CONTROL = 0;
  }

  List data = new ArrayList();
  String data1[] = new String[]{"相片","代工紙","其他","報價單","圖則"};
  int data2[] = new FileUtil().getAllFileSize(data1);
  for(int i = 0;i<data1.length;i++){
    data.add(new String[]{data1[i],data2[i]+"","",""});
  }

  List files = new ArrayList();
  List<String> fileList = new FileUtil().readTxtFileByPath(RECORED_PATH,data1[SHOW_CONTROL]);
  int FILE_SIZE = fileList.size();
  int fileID[] = new int[FILE_SIZE];
  String fileName[] = new String[FILE_SIZE];
  String fileDate[] = new String[FILE_SIZE];
  String fileRemark[] = new String[FILE_SIZE];

  for(int i=0;i<FILE_SIZE;i++){
     Map<String,String> map =new FileStringUtil().getFileDetails(fileList.get(i));
     fileID[i] = i+1;
     fileName[i] = map.get("fileDetail0");
     fileDate[i] = map.get("fileDetail1");
     fileRemark[i] = map.get("fileDetail2");
     files.add(new String[]{fileID[i]+"",fileName[i],fileDate[i],fileRemark[i],""});
  }

  request.setAttribute("data" ,data);
  request.setAttribute("files" ,files);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>" rel="external nofollow" >
<title>Upload</title> 

<!--装载文件-->
<link href="css/uploadify.css" rel="external nofollow" rel="stylesheet" type="text/css" />
<link href="css/Regist.css" rel="external nofollow" type="text/css" />
<link href="css/jquery.ui.all.css" rel="external nofollow" rel="stylesheet">
<script type="text/javascript" src="uploadify/jquery-1.9.1.js"></script>
<script type="text/javascript" src="uploadify/jquery.uploadify.min.js"></script> 

<!--ready事件-->
<script type="text/javascript">
  $(document).ready(function() {
    $("#uploadify").uploadify({
      'method':'get',
      'uploader' : 'servlet/Upload',
      'swf' : 'uploadify/uploadify.swf',
      'cancelImg' : 'img/uploadify-cancel.png',
      'folder' : 'uploads',//您想将文件保存到的路径
      'queueID' : 'fileQueue',//与下面的id对应
      'queueSizeLimit' : 5,
      'fileDesc' : 'rar文件或zip文件',
      'fileExt' : '*.rar;*.zip', //控制可上传文件的扩展名,启用本项时需同时声明fileDesc
      'auto' : false,
      'multi' : false,
      'uploadLimit' : 10,
      'buttonText' : '選擇檔案',
      'removeCompleted':false,
      onUploadStart: function(file) {
      $('#uploadify').uploadify(
      'settings', 'formData', {
      'save_path': escape(document.getElementById("save_type_select").options[document.getElementById("save_type_select").selectedIndex].value),
      'remark':escape(document.getElementById("remark").value)
      });}
      ,
      onUploadSuccess: function (file, data, response) {
        window.location.reload();
      }
    });
  });

  function ReStartJSP(num){
    location.replace("http://localhost:8080/uploadifyTest/index.jsp?num="+num);
  }

  function onload(){
    initOptions();
    ReadTxtFile();
  }

  function initOptions(){
  // alert(isNaN(parseInt(size)));
    var num = <%=data1.length%>;
    for(var i = 0;i<num;i++){
    var optionText = document.getElementById("hidden_"+i).value;
    document.getElementById("save_type_select").add(new Option(optionText,optionText));
    }
  }

  function setOptions(obj){
    var SelectObj = document.getElementById("save_type_select");
    SelectObj.options[parseInt(obj.value)].selected = true;
  }

  function showDIV(obj){

    var div = document.getElementById("fileUploadDIV");
    if(div.style.display == "none"){
      div.style.display = "block";
    }
    setOptions(obj);

  }
  function hindDIV(){
    var div = document.getElementById("fileUploadDIV");
    if(div.style.display == "block"){
      div.style.display = "none";
    }
  }

  function deleteFile(name){
    var showMessage = "c:\\"+"<%=data1[SHOW_CONTROL]%>"+"\\"+name;
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    if(fso.FileExists(showMessage)){
    fso.DeleteFile(showMessage);
    alert("delete success!!");
    location.replace("http://localhost:8080/uploadifyTest/index.jsp?num="+<%=SHOW_CONTROL%>);
    }

  }

</script>
</head> 

<body onload="onload()"> 

 <myTag:iter columnSize="4" files="${files}" data="${data}" />

 </br></br></br>
 <div id="fileUploadDIV" style="display:none">
 <table id="upload_table" >
 <tr>
   <td><select id="save_type_select"></select></td>

   <td><input type="file" name="uploadify" id="uploadify"/> </td>

   <td><label>備註:</label ><input type="text" width="100px" id="remark" value='maah%e4u5848在哪呢你5874'/></td>

   <td><a href="javascript:$('#uploadify').uploadify('upload');" rel="external nofollow"  style="font-size:14px;font-weight:normal">上載</a></td>

   <td><a href="javascript:$('#uploadify').uploadify('cancel'); hindDIV()" rel="external nofollow" style="font-size: 14px; font-weight: normal">取消</a></td>
 </tr>
 </table>
 <div id="fileQueue" ></div>
</div>
</body>
</html>

至此,这个小项目就写到这里,下面是Demo连接

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • uploadify多文件上传参数设置技巧

    比起swfupload,uploadify插件配置使用都更简单,只是刚加载的时候稍微慢了一秒左右. 废话不多说了,直接给大家贴代码了. <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8″ /> <title>php jquery

  • jQuery文件上传控件 Uploadify 详解

    基于jquery的文件上传控件,支持ajax无刷新上传,多个文件同时上传,上传进行进度显示,删除已上传文件. 要求使用jquery1.4或以上版本,flash player 9.0.24以上. 有两个版本,一个用flash,一个是html5.html5的需要付费~所以这里只说flash版本的用法. 官网:http://www.uploadify.com/ 控件截图: 用法: 首先引用下面的文件 <link rel="stylesheet" type="text/css&

  • jQuery.uploadify文件上传组件实例讲解

    1.jquery.uploadify简介 在ASP.NET中上传的控件有很多,比如.NET自带的FileUpload,以及SWFUpload,Uploadify等等,尤其后面两个控件的用户体验比较好,无刷新,带上传进度等等.在最近的短信平台开发中,使用Uploadify进行文件上传. Uploadify官网地址是:http://www.uploadify.com/ 可满足项目开发需求. 下载地址:http://www.uploadify.com/wp-content/uploads/files/

  • ASP.NET文件上传控件Uploadify的使用方法

    对于文件上传来说,有很多种实现方式,如传统的表单方式,现在流行的flash方式,甚至还有纯JS方式,之所以有这些方式来实现文件上传,我想主要原因是因为,传统的上传对于大文件支持不够,因为它是单线程同步机制,当大文件通过HTTP方式发送到服务端时,对于服务端站点的主线程影响比较大,会产生阻塞,所以,现在很多上传控制都是异步,多线程的方式去实现的. 今天来介绍一个文件上传控制,它就是Uploadify,它应该是flash的异步上传工具,对于大文件支持还不错,所以,我选择了它. 相关API介绍 upl

  • php+jQuery.uploadify实现文件上传教程

    这两天用上传的控件,PHP+Jquery今天先介绍这个uploadify,嗯,我今天下载因为我英文不是很好所以我就在网上找的使用教程,我发现好多用不了,我那个去,你看官方文档才知道很多API已经不是以前的API了.今天总结一下给大家,给大家一个提醒最多还是要看官方的http://www.uploadify.com/documentation/! 简单举例一下使用然后我都加上注释给大家,方便大家阅读和使用下载官方的之后直接使用就OK了,当然你需要什么在直接修改就可以了! 复制代码 代码如下: <!

  • uploadify java实现多文件上传和预览

    本文实例为大家分享了java文件上传和预览实现代码,供大家参考,具体内容如下 1.下载uploadify插件 2.index.html <!DOCTYPE html> <html lang="en"> <head> <@head/> <script src="<@path/>/js/uploadify-v3.1/jquery.uploadify-3.1.js"></script> &

  • Javascript使用uploadify来实现多文件上传

    使用uploadify来实现文件上传能够客户端判断文件大小.控制文件上传的类型.实现多文件上传.显示进度条等功能,方便易用,兼容性较好. 本例是把dwz中整合uploadify功能抽取出来的,可以进行单独使用,不一定要遭dwz中才能使用,本例只是为了测试,所以使用静态页面进行测试: 话不多说,代码敬上: 2,html页面的代码 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html&g

  • 详解jQuery uploadify文件上传插件的使用方法

    uploadify这个插件是基于js里面的jquery库写的.结合了ajax和flash,实现了这个多线程上传的功能. 现在最新版为3.2.1. 在线实例 实例中用到的php文件UploaderDemo.php请在页面下方下载 引入文件 <link rel="stylesheet" type="text/css" href="uploadify.css" /> <script type="text/javascript

  • jQuery文件上传插件Uploadify使用指南

    对于HTML5版本会比较好的支持手机浏览器,避免苹果手机Safari浏览器不支持Flash,主要特性:支持多文件上传.HTML5版本可拖拽上传.实时上传进度条显示.强大的参数定制功能,如文件大小.文件类型.按钮图片定义.上传文件脚本等. Flash版本使用方法:1.加载JS和CSS 复制代码 代码如下: <script src="jquery/1.7.1/jquery.min.js" type="text/javascript"></script&

  • ASP.NET多文件上传控件Uploadify的使用方法

    对于Uploadify文件上传之前已经讲过一次(文件上传~Uploadify上传控件),只不过没有涉及到多文件的上传,这回主要说一下多个文件的上传,首先,我们要清楚一个概念,多文件上传前端Uploadify是通过轮训的方式去调用我们的后台upload程序的,所以,对于多文件上传来说,也没什么稀奇的. 下面是文件上传后的缩略图如下 列表的组装使用JS模板,这样对于复杂的HTML结构来说,可以减少拼写错误的出现,关闭是将LI元素从UI元素移除,最后提交时,从UI里检查LI元素,然后对它进行组装,并进

随机推荐