資源簡介
$(".width120").unbind("change");
$(".width120").change(function () {
var id = $(this).attr("id");
id = (id.split("-"))[1];
if ($("#hid-" id).val() == "false") {//文件不在上傳狀態
if ($("#file-" id).val() != "") {
$("#hid-" id).val("true")
$("#UpLoadForm-" id).ajaxSubmit({
success: function (html, status) {
var result = html.replace("<pre>", "");
result = result.replace("</pre>", "");
var img = (result.split(">"))[1];
$("#image-" id).attr('src', img);
$("#loding-" id).text("完成");
list = $(".file");
var isok = true;
for (var i = 0; i < list.length; i ) {
if (list[i].value == "") {
isok = false;
}
}
if (isok) {//添加新的控件
id ;
$("#new").append("<form id='UpLoadForm-" id "' name='UpLoadForm' method='post' enctype='multipart/form-data' action='Update.ashx'><table border='0' cellpadding='0' cellspacing='0' class='upp'><tr><td><input class='width120' type='file' id='file-" id "' name='flUpload' /><p style='display:inline;' id='loding-" id "'>未上傳</p><input id='hid-" id "' type='hidden' value='false'><image style='display:inline;width:100px;height:50px;' id='image-" id "'/></div><br/></td></tr></table></form>");
add();
}
}
});
} else {
alert("請先選擇文件!");
}
$(".width120").change(function () {
var id = $(this).attr("id");
id = (id.split("-"))[1];
if ($("#hid-" id).val() == "false") {//文件不在上傳狀態
if ($("#file-" id).val() != "") {
$("#hid-" id).val("true")
$("#UpLoadForm-" id).ajaxSubmit({
success: function (html, status) {
var result = html.replace("<pre>", "");
result = result.replace("</pre>", "");
var img = (result.split(">"))[1];
$("#image-" id).attr('src', img);
$("#loding-" id).text("完成");
list = $(".file");
var isok = true;
for (var i = 0; i < list.length; i ) {
if (list[i].value == "") {
isok = false;
}
}
if (isok) {//添加新的控件
id ;
$("#new").append("<form id='UpLoadForm-" id "' name='UpLoadForm' method='post' enctype='multipart/form-data' action='Update.ashx'><table border='0' cellpadding='0' cellspacing='0' class='upp'><tr><td><input class='width120' type='file' id='file-" id "' name='flUpload' /><p style='display:inline;' id='loding-" id "'>未上傳</p><input id='hid-" id "' type='hidden' value='false'><image style='display:inline;width:100px;height:50px;' id='image-" id "'/></div><br/></td></tr></table></form>");
add();
}
}
});
} else {
alert("請先選擇文件!");
}
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.IO;
using?System.Linq;
using?System.Net;
using?System.Text;
using?System.Web;
namespace?Test
{
????///?
????///?Update?的摘要說明
????///?
????public?class?Update?:?IHttpHandler
????{
????????public?void?ProcessRequest(HttpContext?context)
????????{
????????????context.Response.ContentType?=?“text/plain“;
????????????//驗證上傳的權限TODO?
????????????string?_fileNamePath?=?““;
????????????try
????????????{
????????????????_fileNamePath?=?context.Request.Files[0].FileName;
????????????????//開始上傳?
????????????????string?_savedFileResult?=?UpLoadImage(_fileNamePath?context);
????????????????context.Response.Write(_savedFileResult);
????????????}
????????????catch
????????????{
????????????????context.Response.Write(“上傳提交出錯“);
????????????}?
????????}
????????public?string?UpLoadImage(string?fileNamePath?HttpContext?context)
????????{
????????????try
????????????{
????????????????st
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2014-11-26?12:05??AjaxUPImage\
?????目錄???????????0??2014-11-26?16:20??AjaxUPImage\Test\
?????目錄???????????0??2014-11-26?12:05??AjaxUPImage\Test\Properties\
?????文件????????1328??2014-11-26?12:05??AjaxUPImage\Test\Properties\AssemblyInfo.cs
?????文件????????5478??2014-11-26?16:00??AjaxUPImage\Test\Test.csproj
?????文件????????1086??2014-11-26?16:00??AjaxUPImage\Test\Test.csproj.user
?????文件??????????84??2014-11-26?14:18??AjaxUPImage\Test\Update.ashx
?????文件????????3986??2014-11-26?16:20??AjaxUPImage\Test\Update.ashx.cs
?????文件????????1245??2014-11-26?12:05??AjaxUPImage\Test\Web.Debug.config
?????文件????????1306??2014-11-26?12:05??AjaxUPImage\Test\Web.Release.config
?????文件?????????311??2014-11-26?12:05??AjaxUPImage\Test\Web.config
?????文件????????4705??2014-11-26?16:20??AjaxUPImage\Test\WebForm1.aspx
?????文件?????????326??2014-11-26?12:05??AjaxUPImage\Test\WebForm1.aspx.cs
?????文件?????????461??2014-11-26?15:00??AjaxUPImage\Test\WebForm1.aspx.designer.cs
?????目錄???????????0??2014-11-26?12:08??AjaxUPImage\Test\bin\
?????文件????????6656??2014-11-26?16:00??AjaxUPImage\Test\bin\Test.dll
?????文件?????????311??2014-11-26?12:05??AjaxUPImage\Test\bin\Test.dll.config
?????文件???????17920??2014-11-26?16:00??AjaxUPImage\Test\bin\Test.pdb
?????目錄???????????0??2014-11-26?16:19??AjaxUPImage\Test\file\
?????文件????????4240??2014-11-26?16:19??AjaxUPImage\Test\file\2014112616191357894077.png
?????文件????????4240??2014-11-26?16:19??AjaxUPImage\Test\file\2014112616195131658159.png
?????文件????????3894??2014-11-26?16:19??AjaxUPImage\Test\file\2014112616195333136697.png
?????文件????????4240??2014-11-26?16:19??AjaxUPImage\Test\file\2014112616195942572308.png
?????文件??????168792??2014-11-26?14:56??AjaxUPImage\Test\jquery-1.4.1.js
?????文件???????85924??2014-11-26?12:09??AjaxUPImage\Test\jquery-1.5.1.min.js
?????文件???????30330??2014-11-26?14:49??AjaxUPImage\Test\jquery.form.js
?????目錄???????????0??2014-11-26?12:05??AjaxUPImage\Test\obj\
?????目錄???????????0??2014-11-26?16:00??AjaxUPImage\Test\obj\Debug\
?????文件????????7815??2014-11-26?16:02??AjaxUPImage\Test\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????目錄???????????0??2014-11-26?16:21??AjaxUPImage\Test\obj\Debug\TempPE\
?????文件?????????256??2014-11-26?15:37??AjaxUPImage\Test\obj\Debug\Test.csproj.FileListAbsolute.txt
............此處省略5個文件信息
- 上一篇:AD 操作 Helper類代碼
- 下一篇:C#方法的調用
評論
共有 條評論