我正在尝试使用 plupload JqueryUI Widget 上传器并尝试使用会话 ID 上传图像并且它保存在相应的会话 ID 下但是当在 completeAll (即当我绑定它们时)事件时我试图使用相同的会话 ID 显示它们的文件名不是正在发生。
谁能告诉我我做错了什么?
这是我的代码:
<script type="text/javascript">
$(function () {
$("#uploader").plupload({
runtimes: 'gears,flash,silverlight,browserplus,html5',
url: 'upload.aspx',
max_file_size: '10mb',
chunk_size: '1mb',
unique_names: true,
// Resize images on clientside if we can
resize: { width: 320, height: 240, quality: 90 },
// Specify what files to browse for
filters: [
{ title: "Image files", extensions: "jpg,gif,png" },
{ title: "Zip files", extensions: "zip" }
],
// Flash settings
flash_swf_url: 'js/plupload.flash.swf',
// Silverlight settings
silverlight_xap_url: 'js/plupload.silverlight.xap'
});
// Client side form validation
$('form').submit(function (e) {
var uploader = $('#uploader').plupload('getUploader');
// Files in queue upload them first
if (uploader.files.length > 0) {
// When all files are uploaded submit form
uploader.bind('StateChanged', function () {
if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) {
$('form')[0].submit();
}
});
uploader.start();
} else
alert('You must at least upload one file.');
return false;
});
var uploader = $('#uploader').plupload('getUploader');
uploader.bind('FileUploaded', function (up, file, res) {
$('#showfilelist').append("<div id=" + file.id + "><a href='uploads/" & Session("ID") & "/" + file.name + "'><br>" + file.name + "</div>");
});
});
</script>
这是处理程序文件:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsNothing(Request.Form("chunk")) = False Then
If Session("ID") Is Nothing Then
Session("ID") = Guid.NewGuid.ToString
IO.Directory.CreateDirectory(Server.MapPath("uploads/" & Session("ID")))
End If
Dim chunk As Integer = Request.Form("chunk")
Dim chunks As Integer = Request.Form("chunks")
Dim filename As String = Request.Form("name")
If chunk = 0 Then
Request.Files(0).SaveAs(Server.MapPath("uploads/") & Session("ID") & "/" & Request.Files(0).FileName)
Else
Dim OutputStream As New IO.FileStream(Server.MapPath("uploads/") & Session("ID") & "/" & Request.Files(0).FileName, IO.FileMode.Append)
Dim InputBytes(Request.Files(0).ContentLength) As Byte
Request.Files(0).InputStream.Read(InputBytes, 0, Request.Files(0).ContentLength)
OutputStream.Write(InputBytes, 0, InputBytes.Length - 1)
OutputStream.Close()
End If
End If
End Sub
在此处显示文件名:
<div id="showfilelist">
</div>