mình làm bằng flash và jquery.
ảnh demo.
yêu cầu cần:
file flash: FlashFileUpload.swf
file cs quản ký phần ghi ảnh: MultiFlashUpload.cs
file js:jquery.MultiFile.js,AC_RunActiveContent.js
code:
Mã:
// According to http://msdn2.microsoft.com/en-us/library/system.web.httppostedfile.aspx
// "Files are uploaded in MIME multipart/form-data format.
// By default, all requests, including form fields and uploaded files,
// larger than 256 KB are buffered to disk, rather than held in server memory."
// So we can use an HttpHandler to handle uploaded files and not have to worry
// about the server recycling the request do to low memory.
// don't forget to increase the MaxRequestLength in the web.config.
// If you server is still giving errors, then something else is wrong.
// I've uploaded a 1.3 gig file without any problems. One thing to note,
// when the SaveAs function is called, it takes time for the server to
// save the file. The larger the file, the longer it takes.
// So if a progress bar is used in the upload, it may read 100%, but the upload won't
// be complete until the file is saved. So it may look like it is stalled, but it
// is not.
using System.IO;
using System.Net;
using System.Web;
using albumanh;
namespace ASP.NET.VN
{
public class MultiFlashUpload : IHttpHandler
{
#region IHttpHandler Members
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
manager mn=new manager();
// Example of using a passed in value in the query string to set a categoryId
// Now you can do anything you need to witht the file.
//int categoryId = 0;
//if (context.Request.QueryString["CategoryID"] != null)
//{
// try
// {
// categoryId = Convert.ToInt32(context.Request.QueryString["CategoryID"]);
// }
// catch (Exception err)
// {
// categoryId = 0;
// }
//}
//if (categoryId > 0)
//{
//}
if (context.Request.Files.Count > 0)
{
// get the applications path
string tempFile = context.Request.PhysicalApplicationPath;
// loop through all the uploaded files
for (int j = 0; j < context.Request.Files.Count; j++)
{
// get the current file
HttpPostedFile uploadFile = context.Request.Files[j];
// if there was a file uploded
if (uploadFile.ContentLength > 0)
{
// save the file to the upload directory
//use this if testing from a classic style upload, ie.
// <form action="Upload.axd" method="post" enctype="multipart/form-data">
// <input type="file" name="fileUpload" />
// <input type="submit" value="Upload" />
//</form>
// this is because flash sends just the filename, where the above
//will send the file path, ie. c:\My Pictures\test1.jpg
//you can use Test.thm to test this page.
//string filename = uploadFile.FileName.Substring(uploadFile.FileName.LastIndexOf("\\"));
//uploadFile.SaveAs(string.Format("{0}{1}{2}", tempFile, "Upload\\", filename));
// use this if using flash to upload
string name = mn.ghiAnh(uploadFile.FileName);
uploadFile.SaveAs(string.Format("{0}{1}{2}", tempFile, "Uploads\\", name));
// HttpPostedFile has an InputStream also. You can pass this to
// a function, or business logic. You can save it a database:
//byte[] fileData = new byte[uploadFile.ContentLength];
//uploadFile.InputStream.Write(fileData, 0, fileData.Length);
// save byte array into database.
// something I do is extract files from a zip file by passing
// the inputStream to a function that uses SharpZipLib found here:
// http://www.icsharpcode.net/OpenSource/SharpZipLib/
// and then save the files to disk.
}
}
}
mn.setAnhNen();
mn.capnhatalbum(idalbum.id.ToString());
// Used as a fix for a bug in mac flash player that makes the
// onComplete event not fire
HttpContext.Current.Response.Write("Thanh Cong! ");
}
#endregion
}
}
thêm flash ở file aspx
Mã:
...
<script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
<script type="text/javascript" src="Scripts/jquery.MultiFile.js"></script>
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
...
<asp:Panel ID="Panel1" runat="server" Visible="False">
<script type="text/javascript">
AC_FL_RunContent( 'id','fileUpload','align','middle','codebase','http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0','height','375','width','575','allowscriptaccess','sameDomain','flashvars','uploadPage=MultiFlashUpload.axd<%=GetFlashVars()%>&completeFunction=UploadComplete()','name','fileUpload','pluginspage','http://www.macromedia.com/go/getflashplayer','quality','high','src','FlashFileUpload','wmode','transparent','movie','FlashFileUpload' ); //end AC code
</script><noscript><object id="fileUpload" align="middle"
classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"
height="375" width="575">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="FlashFileUpload.swf" />
<param name="quality" value="high" />
<param name="wmode" value="transparent" />
<param name="FlashVars"
value="uploadPage=MultiFlashUpload.axd<%=GetFlashVars()%>&completeFunction=UploadComplete()" />
<embed align="middle" allowscriptaccess="sameDomain"
flashvars="uploadPage=MultiFlashUpload.axd<%=GetFlashVars()%>&completeFunction=UploadComplete()"
height="375" name="fileUpload"
pluginspage="http://www.macromedia.com/go/getflashplayer" quality="high"
src="FlashFileUpload.swf" type="application/x-shockwave-flash" width="575"
wmode="transparent"></embed>
</object><oscript>
<asp:LinkButton ID="LinkButton1" runat="server" CssClass="dongupload"
onclick="LinkButton1_Click">Đóng Upload</asp:LinkButton>
</asp:Panel>
mình làm trên xml lên các bạn dowload code về tham khảo nhé.thắc mắc post lên đây.cái này là cái assignment môn begin asp.net của mình.còn mấy chức năng quản lý xóa,di chuyển ảnh chửa làm xong.
có thể tham khảo thêm flash ở đây: http://www.codeproject.com/Articles/...ar-Using-Flash
http://boyprodx.blogspot.com/2009/05...flash-swf.html
Hướng dẫn vui nhộn về phương tiện nong lỗ đít Thuốc giãn hậu môn nghe có vẻ đáng sợ, nhưng đừng sợ! Hướng dẫn này sẽ đưa bạn qua hành trình hích khi dùng dụng cụ làm giãn lỗ đít, khiến nó trở...
Hướng dẫn vui nhộn về sản phẩm làm...