1.download swfupload.js
@{
ViewBag.Title = "AddProduct";
}
<h2>
AddProduct</h2>
<div>
<fieldset>
<legend>Add product</legend>
<div class="form_item">
<div class="item_title">
product name</div>
<div class="item_input">
<input type="text" id="name" /></div>
</div>
<div class="form_item">
<div class="item_title">
product catagory</div>
<div class="item_input">
<select>
<option value="">please select</option>
</select>
<a href="#">click here to add or edit catagory</a></div>
</div>
<div class="form_item">
<div class="item_title">
product description</div>
<div class="item_input">
<textarea id="description" rows="10" cols="100"></textarea></div>
</div>
<div class="form_item">
<div class="item_title">
product price</div>
<div class="item_input">
<input type="text" id="price" /></div>
</div>
<div class="form_item">
<div class="item_title"> product image</div>
<div>
<span id="spanButtonPlaceHolder"></span>
<input id="btnCancel" type="button" value="Cancel All Uploads" onclick="swfu.cancelQueue();" disabled="disabled" style="margin-left: 2px; font-size: 8pt; height: 29px;" />
</div>
<div class="fieldset flash" id="fsUploadProgress">
<span class="legend">Upload Queue</span>
</div>
<div id="divStatus">0 Files Uploaded</div>
</div>
<div class="form_item">
<div class="item_input">
<input type="button" value="confirm" />
<input type="button" value="reset" /></div>
</div>
</fieldset>
</div>
<script src="http://www.cnblogs.com/Scripts/swfupload/fileprogress.js" type="text/javascript"></script>
<script src="http://www.cnblogs.com/Scripts/swfupload/handlers.js" type="text/javascript"></script>
<script src="http://www.cnblogs.com/Scripts/swfupload/swfupload.js" type="text/javascript"></script>
<script src="http://www.cnblogs.com/Scripts/swfupload/swfupload.queue.js" type="text/javascript"></script>
<script type="text/javascript">
var swfu;
window.onload = function () {
var settings = {
flash_url: '@Url.Content("~/Scripts/Swfupload/swfupload.swf")',
upload_url: '/admin/imageupload',
post_params: { "PHPSESSID": "" },
file_size_limit: "100 MB",
file_types: "*.*",
file_types_description: "All Files",
file_upload_limit: 100,
file_queue_limit: 0,
custom_settings: {
progressTarget: "fsUploadProgress",
cancelButtonId: "btnCancel"
},
debug: false,
// Button settings
button_image_url: '@Url.Content("~/Scripts/Swfupload/images/XPButtonNoText_160x22.png")', //flash按钮背景,注意自己的路径。
button_ "65",
button_height: "29",
button_placeholder_id: "spanButtonPlaceHolder",
button_text: '<span class="theFont">Hello</span>',
button_text_style: ".theFont { font-size: 16; }",
button_text_left_padding: 12,
button_text_top_padding: 3,
// The event handler functions are defined in handlers.js
file_queued_handler: fileQueued,
file_queue_error_handler: fileQueueError,
file_dialog_complete_handler: fileDialogComplete,
upload_start_handler: uploadStart,
upload_progress_handler: uploadProgress,
upload_error_handler: uploadError,
upload_success_handler: uploadSuccess,
upload_complete_handler: uploadComplete,
queue_complete_handler: queueComplete // Queue plugin event
};
swfu = new SWFUpload(settings);
};
</script>
2.in action,implete multi file upload
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;
namespace PlantWeb.Controllers
{
public class AdminController : Controller
{
//
// GET: /Admin/
public ActionResult Add()
{
return View();
}
public ActionResult Edit()
{
return View();
}
public ActionResult ImageUpload()
{
int files = 0;
string root_path = AppDomain.CurrentDomain.BaseDirectory;
string upload_path = root_path + @"UploadImage\product";
string upload_filename = "";
if (!Directory.Exists(upload_path))
{
Directory.CreateDirectory(upload_path);
}
foreach (string filename in Request.Files)
{
//保存的本地
var file = Request.Files[filename];
upload_filename = file.FileName;
file.SaveAs(upload_path + "\\" + upload_filename);
files++;
//保存到数据库
//byte[] buffer;
//buffer = new byte[file.InputStream.Length];
//file.InputStream.Read(buffer, 0, buffer.Length);
}
return Content("message from server file count: " + files, "text/plain");
}
}
}