uploadify文件名乱码|php上传文件后名字变了如何让文件名不变上传成功后能否获取文件链接

uploadify文件名乱码|php上传文件后名字变了如何让文件名不变上传成功后能否获取文件链接的第1张示图

⑴ java ssh框架中怎么上传图片

package com.lilian.framework.servlet;import java.io.File;import java.io.IOException;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Date;import java.util.Iterator;import java.util.List;import java.util.UUID;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.lilian.business.common.model.CmResource;import com.lilian.framework.utils.FileLoadUtil;/** * 通用上传组件(可以使用uploadify等上传组件上传资源) * @author Ares */public class FileUploadServlet extends HttpServlet {private static final long serialVersionUID = -7933946015372885027L;public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {this.doProcess(request, response);}public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {this.doProcess(request, response);}public void doProcess(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {response.setContentType("text/html; charset=utf-8");// 保存后的文件名String bornName = "";//源文件名String fileName = "";//文件名String fileFormat = "";//文件格式short fileType = 1;//文件类型Long fileSize = 0l;//文件大小String hostAddr = "";//主机地址(主机IP/域名)String virtualAddr = "";//虚拟地址(相对路径)String urlPath = "";//URL地址(访问路径)// 通过时间戳散列目录存储SimpleDateFormat formatter = new SimpleDateFormat("yyyyMM/ddHH/");Date curDate = new Date(System.currentTimeMillis());// 获取当前时间String fileFolder = formatter.format(curDate);hostAddr = FileLoadUtil.getKeyValueByKeyName("file.upload.hostadd");//virtualAddr = FileLoadUtil.getKeyValueByKeyName("file.upload.virtualdir.image") + fileFolder;String uploadType = request.getParameter("uploadType");if(uploadType!=null && !uploadType.equals("")){if(uploadType.equals("1")){virtualAddr = FileLoadUtil.getKeyValueByKeyName("file.upload.virtualdir.image") + fileFolder;}else if(uploadType.equals("2")){virtualAddr = FileLoadUtil.getKeyValueByKeyName("file.upload.virtualdir.config") + fileFolder;}else{response.getWriter().print("文件上传失败,上传类型不存在!");return;}}else{response.getWriter().print("文件上传失败,没有上传类型!");return;}//urlPath = SystemLocation.getWebrootpath() + "/" + virtualAddr;urlPath = hostAddr + virtualAddr;// 文件存放的目录//String savePath = FileUtil.getUploadFilePath();String savePath = FileLoadUtil.getKeyValueByKeyName("file.upload.path") + virtualAddr;// 这里还可以添加有业务规则的文件目录,比如允许每个用户有自己的上传文件目录File tempDirPath = new File(savePath);if (!tempDirPath.exists()) {tempDirPath.mkdirs();}// 创建磁盘文件工厂DiskFileItemFactory fac = new DiskFileItemFactory();// 创建servlet文件上传组件ServletFileUpload upload = new ServletFileUpload(fac);// 设置charset为utf-8,上传中文文件名不会产生乱码upload.setHeaderEncoding("UTF-8");// 文件列表List fileList = null;// 解析request从而得到前台传过来的文件try {fileList = upload.parseRequest(request);} catch (FileUploadException ex) {ex.printStackTrace();return;}// 遍历从前台得到的文件列表Iterator<FileItem> it = fileList.iterator();List<CmResource> cmResourceList = new ArrayList<CmResource>();while (it.hasNext()) {FileItem item = (FileItem) it.next();if (!item.isFormField()) {fileName = item.getName();fileSize = item.getSize();bornName = fileName.substring(0, fileName.lastIndexOf("."));if (fileName == null || fileName.trim().equals("")) {continue;}// 扩展名格式:if (fileName.lastIndexOf(".") >= 0) {fileFormat = fileName.substring(fileName.lastIndexOf(".")+1);}File file = null;do {// 生成文件名:fileName = UUID.randomUUID().toString() + "." + fileFormat;file = new File(savePath + fileName);} while (file.exists());File saveFile = new File(savePath + fileName);try {item.write(saveFile);} catch (Exception e) {e.printStackTrace();}System.out.println("***************************************************************");System.out.println("bornName: " + bornName);System.out.println("fileName: " + fileName);System.out.println("fileFormat: " + fileFormat);System.out.println("fileType: " + fileType);System.out.println("fileSize: " + fileSize.longValue());System.out.println("hostAdd: " + hostAddr);System.out.println("virtualAddr: " + virtualAddr);System.out.println("urlPath: " + urlPath);System.out.println("imageURL: " + hostAddr + virtualAddr + fileName);System.out.println("***************************************************************");CmResource cmResource = new CmResource();cmResource.setBornName(bornName);cmResource.setFileName(fileName);cmResource.setFileFormat(fileFormat);cmResource.setFileType(fileType);cmResource.setFileSize(fileSize);cmResource.setHostAddr(hostAddr);cmResource.setVirtualAddr(virtualAddr);cmResource.setUrlPath(urlPath);cmResourceList.add(cmResource);}}// 将文件的 相对路径+源名称+文件大小 返回给response流。request.setAttribute("cmResourceList", cmResourceList);response.setContentType("text/html; charset=utf-8");response.getWriter().print("文件上传成功!");}}万能通用

⑵ uploadify 怎么改文件名,而且如果文件名是中文的话就不能上传了

jQuery.Uploadify 上传中文文件名出现乱码解决,无非是程序编码和系统编码不一致造成的,于是尝试修改uploadify.php文件,将:move_uploaded_file($tempFile,$targetFile);修改为:move_uploaded_file($tempFile,iconv(“UTF-8″,”gb2312″, $targetFile));

⑶ php上传文件后名字变了,如何让文件名不变,上传成功后能否获取文件链接

function uploadify(){$targetFolder = '/uploads/';$verifyToken = md5('unique_salt' . $_POST['timestamp']);if (!empty($_FILES) && $_POST['token'] == $verifyToken) {$tempFile = $_FILES['Filedata']['tmp_name'];$targetPath = $targetFolder;$savePath=$targetFolder.$_FILES['Filedata']['name'];$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];$fileTypes = array('aac','flac','mar','wma','mp3','ape','ogg');$fileParts = pathinfo($_FILES['Filedata']['name']);if (in_array($fileParts['extension'],$fileTypes)) {move_uploaded_file($tempFile,iconv("UTF-8","gb2312", $targetFile));echo $savePath;}else{echo 'Invalid file type.';}}}这个("UTF-8","gb2312", $targetFile)保持中文不被乱码或者中文上传不了问题。

⑷ uploadify上传,中文名文件 上传后文件名是乱码(ie下)

检查一下你的flash版本,adobe最近的有一个版本有这个问题,不过现在应该有一个新的版本出来了,更新一下试试

⑸ uploadify的div和object不在同一位置

本人也遇到这个问题,找到一比较“简单粗暴”的方法,改动object的位置样式,left 、top来让它和div对应起来,前提是你要将他们相应父级节点样式设置为relative。

⑹ jquery 多个 上传文件教程

jquery 实现多个上传文件教程:

首先创建解决方案,添加jquery的js和一些资源文件(如图片和进度条显示等):

jquery-1.3.2.min.jsjquery.uploadify.v2.1.0.jsjquery.uploadify.v2.1.0.min.jsswfobject.jsuploadify.css

1、页面的基本代码如下

这里用的是aspx页面(html也是也可的)

页面中引入的js和js函数如下:

<scriptsrc="js/jquery-1.3.2.min.js"type="text/javascript"></script><scriptsrc="js/jquery.uploadify.v2.1.0.js"type="text/javascript"></script><scriptsrc="js/jquery.uploadify.v2.1.0.min.js"type="text/javascript"></script><scriptsrc="js/swfobject.js"type="text/javascript"></script><linkhref="css/uploadify.css"rel="stylesheet"type="text/css"/></script>

js函数:

<scripttype="text/javascript">$(document).ready(function(){$("#uploadify").uploadify({'uploader':'image/uploadify.swf',//uploadify.swf文件的相对路径,该swf文件是一个带有文字BROWSE的按钮,点击后淡出打开文件对话框'script':'Handler1.ashx',//script:后台处理程序的相对路径'cancelImg':'image/cancel.png','buttenText':'请选择文件',//浏览按钮的文本,默认值:BROWSE。'sizeLimit':999999999,//文件大小显示'floder':'Uploader',//上传文件存放的目录'queueID':'fileQueue',//文件队列的ID,该ID与存放文件队列的div的ID一致'queueSizeLimit':120,//上传文件个数限制'progressData':'speed',//上传速度显示'auto':false,//是否自动上传'multi':true,//是否多文件上传//'onSelect':function(e,queueId,fileObj){//alert("唯一标识:"+queueId+""+//"文件名:"+fileObj.name+""+//"文件大小:"+fileObj.size+""+//"创建时间:"+fileObj.creationDate+""+//"最后修改时间:"+fileObj.modificationDate+""+//"文件类型:"+fileObj.type);//}'onQueueComplete':function(queueData){alert("文件上传成功!");return;}});});

页面中的控件代码:

<body><formid="form1"runat="server"><divid="fileQueue"></div><div><p><inputtype="file"name="uploadify"id="uploadify"/><inputid="Button1"type="button"value="上传"onclick="javascript:$('#uploadify').uploadifyUpload()"/><inputid="Button2"type="button"value="取消"onclick="javascript:$('#uploadify').uploadifyClearQueue()"/></p></div></form></body>

函数主要参数:

$(document).ready(function(){$('#fileInput1').fileUpload({'uploader':'uploader.swf',//不多讲了'script':'/AjaxByJQuery/file.do',//处理Action'cancelImg':'cancel.png','folder':'',//服务端默认保存路径'scriptData':{'methed':'uploadFile','arg1','value1'},//向后台传递参数,methed,arg1为参数名,uploadFile,value1为对应的参数值,服务端通过request["arg1"]'buttonText':'UpLoadFile',//按钮显示文字,不支持中文,解决方案见下//'buttonImg':'图片路径',//通过设置背景图片解决中文问题,就是把背景图做成按钮的样子'multi':'true',//多文件上传开关'fileExt':'*.xls;*.csv',//文件过滤器'fileDesc':'.xls',//文件过滤器详解见文档'onComplete':function(event,queueID,file,serverData,data){//serverData为服务器端返回的字符串值alert(serverData);}});});

后台一般处理文件:

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.IO;usingSystem.Net;usingSystem.Web;usingSystem.Web.Services;namespacefupload{///<summary>///Handler1的摘要说明///</summary>publicclassHandler1:IHttpHandler{publicvoidProcessRequest(HttpContextcontext){context.Response.ContentType="text/plain";HttpPostedFilefile=context.Request.Files["Filedata"];//对客户端文件的访问stringuploadPath=HttpContext.Current.Server.MapPath(@context.Request["folder"])+"\";//服务器端文件保存路径if(file!=null){if(!Directory.Exists(uploadPath)){Directory.CreateDirectory(uploadPath);//创建服务端文件夹}file.SaveAs(uploadPath+file.FileName);//保存文件context.Response.Write("上传成功");}else{context.Response.Write("0");}}publicboolIsReusable{get{returnfalse;}}}}

以上方式基本可以实现多文件的上传,大文件大小是在控制在10M以下/。

⑺ uploadify2.1版本,c#后台怎么获取上传文件的路径和文件名

更改upload.ashx这个文件public class _upload : IHttpHandler, IReadOnlySessionState, IRequiresSessionState这样就可以使用Session然后把上传文件的路径和文件名保存起来,在c#后台获取即可

⑻ jquery 的 uploadify如何将已经上传的文件删除

jQuery部分: 'onComplete':function (event, queueID, fileObj, response, data) //上传一次 { respnose //获取的就是下面PHP代码传递过来的参数。 }PHP部分(上传文件PHP:uploadify.php):move_uploaded_file($tempFile,iconv("UTF-8","gb2312", $targetFile)); //上传文件.echo $targetFile; //输出上传文件名.

⑼ .net网站,文件上传控件

uploadify控件js: $("#uploadify_HB_SZGT").uploadify({ 'swf': '../JS/uploadify/uploadify.swf', 'uploader': '../JS/uploadify/upload_HB_SZGT.ashx', 'buttonText': '添加附件', 'buttonClass': 'button-class', 'buttonCursor': 'hand', 'fileSizeLimit': '2097152KB', 'fileTypeExts': '*.gif; *.jpg; *.png;*.pdf;*.txt;*.doc;*.wps;*.xls;*.jpeg', 'folder': 'dzka_ba', 'queueID': 'fileQueue', 'auto': true, 'multi': false, 'fileObjName': 'Filedata', 'method': 'GET', 'removeCompleted': false, 'onUploadStart': function (file) { //设置值 var fj_sbxh = $("#ContentPlaceHolder1_hidSBXH").val(); if (fj_sbxh == "") { alert("请您先登录"); return; } var fj_dzzlzlbh = $("#slDZZLZL").val(); //单证种类编号 var fj_dzzlzlmc = $("#slDZZLZL").find("option:selected").text(); //单证种类名称 var fj_sblx = $("#txtSBLX").val(); //申报类型 var fj_QFRQ = ($("#txtQFRQ").val() == "") ? "E" : $("#txtQFRQ").val(); //签发日期 var fj_YXQ = ($("#txtYXQ").val() == "") ? "E" : $("#txtYXQ").val(); //有效期 var fj_SFHL = ($("#txtSFHL").val()=="") ? "E" : $("#txtSFHL").val();//水份含量 var fj_CXGJZ = ($("#txtCXGJZ").val() == "") ? "E" : $("#txtCXGJZ").val(); //查询关键字 var fj_WJLX = $("#slWJLX").val(); //文件类型 $("#uploadify_HB_SZGT").uploadify("settings", "formData", { 'cs_dzzlzlbh': fj_dzzlzlbh, 'cs_dzzlzlmc': fj_dzzlzlmc, 'cs_sblx': fj_sblx,'cs_SFHL':fj_SFHL, 'cs_QFRQ': fj_QFRQ, 'cs_YXQ': fj_YXQ,'cs_CXGJZ': fj_CXGJZ, 'cs_WJLX': fj_WJLX, 'cs_sbxh': fj_sbxh}); } });ashx: public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Charset = "utf-8"; string sbxh = context.Request.Form["cs_sbxh"].ToString(); string dzzlzlbh = context.Request.Form["cs_dzzlzlbh"].ToString(); string dzzlzlmc = context.Request.Form["cs_dzzlzlmc"].ToString(); string sblx = context.Request.Form["cs_sblx"].ToString(); string first_CXGJZ = context.Request.Form["cs_CXGJZ"].ToString(); string CXGJZ = (first_CXGJZ == "E") ? "" : first_CXGJZ; string WJLX = context.Request.Form["cs_WJLX"].ToString(); HttpPostedFile file = context.Request.Files["Filedata"]; string uploadPath = HttpContext.Current.Server.MapPath(context.Request.ApplicationPath) + "czkh_file\\wxp\\cs\\"; if (file != null) { if (!Directory.Exists(uploadPath)) { Directory.CreateDirectory(uploadPath); } //如果Session不能用的话,用Cache //检测是否存在相同文件名的文件 string filename = file.FileName.ToString(); string hz = filename.Substring(filename.LastIndexOf("."));//后缀名 //“DZKA_WXPHS_”+申报序号+“_”+单证种类编号+“_”+顺序号+“.”+文件后缀 string fileSavePath = Function.getUniqueName(uploadPath + "DZKA_WXPCS_" + sbxh + "_" + dzzlzlbh+ hz); string wjccmc = fileSavePath.Substring(fileSavePath.LastIndexOf("\\")+1);//文件存储名称 string wjxdlj = "/czkh_file/wxp/cs";//文件相对路径 file.SaveAs(fileSavePath); int zlxh; DataTable dtxh = C_WXP_FSZL.getmaxXH(new OracleParameter(":SBXH", sbxh), new OracleParameter(":SBLX", sblx), new OracleParameter(":DZZLBH", dzzlzlbh)); if (dtxh.Rows.Count > 0) { string strxh = dtxh.Rows[0]["XH"].ToString(); if (string.IsNullOrEmpty(strxh)) { zlxh = 1; } else { zlxh = Convert.ToInt32(strxh) + 1; } } else { zlxh = 1; } C_WXP_FSZL.insert(new OracleParameter(":SBXH", sbxh), new OracleParameter(":SBLX", sblx), new OracleParameter(":DZZLBH", dzzlzlbh), new OracleParameter(":HWXH", "0"), new OracleParameter(":XH",zlxh), new OracleParameter(":ZLBH", ""), new OracleParameter(":ZLMC", dzzlzlmc), new OracleParameter(":JYBH", ""), new OracleParameter(":QFRQ", ""), new OracleParameter(":YXQ", ""), new OracleParameter(":NJRQ", ""), new OracleParameter(":HWMC", ""), new OracleParameter(":SDLB", ""), new OracleParameter(":WJMC", filename), new OracleParameter(":ZJS", ""), new OracleParameter(":BCSYJS", ""), new OracleParameter(":SYJS", ""), new OracleParameter(":GS", ""), new OracleParameter(":SFCFSY", ""), new OracleParameter(":YFHL", ""), new OracleParameter(":SFHL", ""), new OracleParameter(":DD", ""), new OracleParameter(":SJ", ""), new OracleParameter(":SFYQX", ""), new OracleParameter(":QXJZQK", ""), new OracleParameter(":MC", ""), new OracleParameter(":SFJGJY", ""), new OracleParameter(":JYRQ", ""), new OracleParameter(":ZHBZFA", ""), new OracleParameter(":WJXDLJ",wjxdlj), new OracleParameter(":WJCCMC",wjccmc)); //下面这句代码缺少的话,上传成功后上传队列的显示不会自动消失 context.Response.Write("1"); } else { context.Response.Write("0"); } }

⑽ jquery插件 uploadify的buttonImg问题

'plugin/uploadify/selectHead.jpg'路径错误..前面加跟斜杠 '/plugin/uploadify/selectHead.jpg'我正在弄这个东西、对了哥们请问一下的这个'buttonText': '选择头像',怎么可以显示汉字呢。我打汉字显示的是乱码。我用的2.1.4。。。。是版本不同还是你采用了其他方法?求教一下

未经允许不得转载:山九号 » uploadify文件名乱码|php上传文件后名字变了如何让文件名不变上传成功后能否获取文件链接

赞 (0)