首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

swfUpload范例

2012-09-03 
swfUpload实例?很好的实例:?官方网站:http://swfupload.org/??1. 第一步:需要引入的css??? link hrefcs

swfUpload实例

swfUpload范例?很好的实例:

?

官方网站:

http://swfupload.org/

?

?

1. 第一步:需要引入的css

??? <link href="css/default.css" rel="stylesheet" type="text/css" />

2. 第二步:需要引入的js

?? <script type="text/javascript" src="js/swfupload.js"></script>
?? <script type="text/javascript" src="js/swfupload.queue.js"></script>
? ?<script type="text/javascript" src="js/fileprogress.js"></script>
? ?<script type="text/javascript" src="js/handlers.js"></script>

?

3.第三步:页面设置的swfupload控件的相关属性:

<script type="text/javascript">
??var swfu;

??window.onload = function() {
???var settings = {
????flash_url : "js/swfupload.swf",??//?调用的上传的flash控件
????upload_url: "${pageContext.request.contextPath}/personcenter/axtxcc/doUpload.action",??? ?//? 后台调用的文件处理程序 注意:配置不正确的话,易导致404错误
????file_size_limit : "1024 MB",????? ?//??所选文件的最大值
????file_types : "*.*",??????????????????? ?//? 限定所上传文件的类型
????file_types_description : "All Files",
????file_upload_limit : 100,?????????? ?//? 设置所上传文件最大个数
????file_queue_limit : 0,??????????????? ?//? 设置上传列表中的最大个数 0:不限制
????custom_settings : {??????????????? ?//??用户自定义设置
?????progressTarget : "fsUploadProgress",
?????uploadButtonId : "btnUpload",
?????cancelButtonId : "btnCancel"
????},
????debug: false,
????auto_upload:false,????????????????? //? 设置自动上传为false

?

????// Button settings???按钮的设置
????button_image_url: "images/TestImageNoText_65x29.png",
????button_width: "65",
????button_height: "29",
????button_placeholder_id: "spanButtonPlaceHolder",
????button_text: '<span action="uploadFile.do" method="post"
???enctype="multipart/form-data">
???<div id="content">
????<div width="16" height="16" />
??????文件上传
?????</div>
????</div>
????<div id="fsUploadProgress">
??????<p>
???????<span type="button" value="上 传"
?????????onclick="swfu.startUpload();"
?????????style="margin-left: 20px; margin-bottom: 10px" />
?????????
???????<input id="btnCancel" type="button" height="29" value="取消上传"
????????onclick="swfu.cancelQueue();"
????????style="margin-left: 20px; margin-bottom: 10px" />
??????</div>
?????</div>
????</div>
???</div>
??</form>
?</body>

?

5:第五步:后台的处理代码:

// 上传文件,并将文件信息保存到数据库中
?public String doUpload() {
??try {

???if (file != null) {

????// 将文件名解码
??? /*ServletActionContext.getRequest().setCharacterEncoding("gbk");
???? String fileFName = ServletActionContext.getRequest()
??????.getParameter("fileFName");
??????? String title =URLDecoder.decode(fileFName, "UTF-8");
????????????? */

????String realpath = ServletActionContext.getServletContext().getRealPath(StringContonts.FILE_AXT_PATH);
????
????// 将文件上传到文件服务器上 begin
????File savefile = new File(new File(realpath), fileFileName);
????
????// 判断目录是否存在,不存在,创建目录
????if (!savefile.getParentFile().exists())
?????savefile.getParentFile().mkdirs();
????FileUtils.copyFile(file, savefile);
????// 将文件上传到文件服务器上 end
????return "success";
???} else {
????return "error";
???}

??} catch (Exception e) {
???// TODO Auto-generated catch block
???e.printStackTrace();

???return "error";
??}
?}

?

6. 第六步 配置文件:

<!-- swf文件上传测试??注意:result的返回路径一定要配置正确,否则报404错误 -->?
??<action name="doUpload" method="doUpload">
???<result name="success">/personcenter/aixuetang/course/swfupload.jsp</result>
???<result name="error">/personcenter/aixuetang/course/swfupload.jsp</result>
??</action>?

?

热点排行