我uploadify
在我的 MVC3 项目中使用。上传多个文件并保存到文件夹也可以正常工作。
如何将上传文件的路径传递给控制器动作?-- 我需要将它传递给ExtractingZip
我的控制器的操作。
为了提取.zip
文件的内容,我使用了 DotNetZip Library。
这是我到目前为止所尝试的。
$('#file_upload').uploadify({
'checkExisting': 'Content/uploadify/check-exists.php',
'swf': '/Content/uploadify/uploadify.swf',
'uploader': '/Home/Index',
'auto': false,
'buttonText': 'Browse',
'fileTypeExts': '*.jpg;*.jpeg;*.png;*.gif;*.zip',
'removeCompleted': false,
'onSelect': function (file) {
if (file.type == ".zip") {
debugger;
$.ajax({
type: 'POST',
dataType: 'json',
url: '@Url.Action("ExtractingZip", "Home")',
data: ({ fileName: file.name}), // I dont see a file.path to pass it to controller
success: function (result) {
alert('Success');
},
error: function (result) {
alert('error');
}
});
}
}
});
这是我的控制器操作:
[HttpPost]
public ActionResult ExtractingZip(string fileName,string filePath, HttpPostedFileBase fileData)
{
string zipToUnpack = @"C:\Users\Public\Pictures\Sample Pictures\images.zip";// I'm unable to get the filePath so i'm using the path.
string unpackDirectory = System.IO.Path.GetTempPath();
using (ZipFile zip1 = ZipFile.Read(zipToUnpack))
{
// here, we extract every entry, but we could extract conditionally
// based on entry name, size, date, checkbox status, etc.
var collections = zip1.SelectEntries("name=*.jpg;*.jpeg;*.png;*.gif;");
foreach (var item in collections)
{
item.Extract(unpackDirectory, ExtractExistingFileAction.OverwriteSilently);
}
}
return Json(true);
}
[HttpPost]
public ActionResult Index(IEnumerable<HttpPostedFileBase> fileData)
{
foreach (var file in fileData)
{
if (file.ContentLength > 0)
{
string currpath;
currpath = Path.Combine(Server.MapPath("~/Images/User3"), file.FileName);
//save to a physical location
file.SaveAs(currpath);
}
}
}