One of the three methods for uploading Avatar screenshots (an easy-to-use flash plug-in) (asp.net) and flashasp.net

Source: Internet
Author: User

One of the three ways to upload an Avatar (an easy-to-use flash plug-in) (asp.net), flashasp.net

Flash has a copyright statement, which is not suitable for commercial development. This is the official website address: http://www.hdfu.net/

This article referred to the http://blog.csdn.net/yafei450225664/article/details/12855915 and added their own parsing, for later reference.

The demo package provided on the official website contains the php, jsp, asp, and aspx demos.

Program is, does not work for the program. Upfile. aspx is the background file for uploading. In fact, we can use a general processing program instead of aspx, and there is no need to write aspx. The actual function of xml is unknown and does not need to be modified.

In 2.demo.html, there are two layers. altContent stores flash and it is recommended that you do not modify the content. We only need to modify the reference path and default image in flash. avatar_priview is used to display the uploaded image, can be deleted. In JS, The uploadevent is successfully uploaded and executed. status indicates the response message value. If 1 is returned, the message is successfully executed.

<Script type = "text/javascript"> function uploadevent (status, picUrl, callbackdata) {// alert (picUrl); // backend storage image // alert (callbackdata ); status + = ''; switch (status) {case '1': var time = new Date (). getTime (); var filename162 = picUrl + '_162.jpg '; var filename48 = picUrl + '_48.jpg'; var filename20 = picUrl + "_0000jpg"; document. getElementById ('Avatar _ priview '). innerHTML = "avatar 1: <br/> Avatar 2: <br/> Avatar 3: "; break; case'-1': window. location. reload (); break; default: window. location. reload () ;}</script>View Code

This code is only used to display images uploaded successfully. You can modify the code as needed.

3.The code in HTML is as follows:

<Div id = "altContent"> <object id = "myMovieName" classid = "clsid: d27CDB6E-AE6D-11cf-96B8-444553540000 "codebase =" http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0 "height =" 450 "width =" 650 "> <param name =" movie "value =" avatar.swf "/> <param name =" quality "value = "high"/> <param name = "bgcolor" value = "# FFFFFF"/> <param name = "flashvars" value = "imgUrl =. /default.jpg & amp; uploadUrl =. /upfile. aspx & amp; uploadSrc = false "/> <embed align =" "allowscriptaccess =" always "bgcolor =" # FFFFFF "flashvars =" imgUrl =. /default.jpg & amp; uploadUrl =. /upfile. aspx & amp; uploadSrc = false "height =" 450 "name =" myMovieName "pluginspage =" http://www.macromedia.com/go/getflashplayer "quality =" high "src = ". /avatar.swf "type =" application/x-shockwave-flash "width =" 650 "wmode =" transparent "> </embed> </EMBED> </object> </div> <div id = "avatar_priview"> </div>View Code

<Embed> </embed> the tag code is linked to the avatar.swf and upfile. aspx background code and default photos, which can be modified as needed.

4. Background code

<% @ Import NameSpace = "System. IO" %>
<% @ Import NameSpace = "System" %>
<% @ Page Language = "C #" %>
<%


DateTime dtStart = TimeZone. CurrentTimeZone. ToLocalTime (new DateTime (1970, 1, 1 ));
DateTime dtNow = DateTime. Parse (DateTime. Now. ToString ());
TimeSpan toNow = dtNow. Subtract (dtStart );
String timeStamp = toNow. Ticks. ToString ();
TimeStamp = timeStamp. Substring (0, timeStamp. Length-7 );


String savePath = "./";
String savePicName = timeStamp;


String file_src = savePath + savePicName + "_src.jpg ";
String filename162 = savePath + savePicName + "_162.jpg ";
String filename48 = savePath + savePicName + "_48.jpg ";
String filename20 = savePath + savePicName + "_0000jpg ";

// Obtain the source image and the three images after modification:
String pic = Request. Form ["pic"];
String pic1 = Request. Form ["pic1"];
String pic2 = Request. Form ["pic2"];
String pic3 = Request. Form ["pic3"];

/* And save it through File. Of course, if you only need an image, you can delete unnecessary code or modify the address for saving the image. With the image address, we can directly store the image address in the database.

Note that the response message is returned.

Response. write ("{\" status \ ": 1}"); it cannot be modified. If it is changed to another value, it can be uploaded successfully in the background, however, the front-end cannot respond to the upload success. The upload success dialog box cannot be displayed.
If we need to return the path processed by the background to the foreground, we can use Session or static variables to save the value in the background. */

// Source Image
If (pic. Length = 0 ){
} Else {
Byte [] bytes = Convert. FromBase64String (pic); // encodes binary into an array of eight unsigned integers.

FileStream fs = new FileStream (Server. MapPath (file_src), System. IO. FileMode. Create );
Fs. Write (bytes, 0, bytes. Length );
Fs. Close ();
}

Byte [] bytes1 = Convert. FromBase64String (pic1); // encodes binary into an array of 8-bit unsigned integers.
Byte [] bytes2 = Convert. FromBase64String (pic2); // encodes binary into an array of 8-bit unsigned integers.
Byte [] bytes3 = Convert. FromBase64String (pic3); // encodes binary into an array of 8-bit unsigned integers.

 

// Figure 1
FileStream fs1 = new FileStream (Server. MapPath (filename162), System. IO. FileMode. Create );
Fs1.Write (bytes1, 0, bytes1.Length );
Fs1.Close ();

// Figure 2
FileStream fs2 = new FileStream (Server. MapPath (filename48), System. IO. FileMode. Create );
Fs2.Write (bytes2, 0, bytes2.Length );
Fs2.Close ();

// Figure 3
FileStream fs3 = new FileStream (Server. MapPath (filename20), System. IO. FileMode. Create );
Fs3.Write (bytes3, 0, bytes3.Length );
Fs3.Close ();

String picUrl = savePath + savePicName;

Response. Write ("{\" status \ ": 1 ,");
Response. Write ("\" picUrl \ ": \" "+ picUrl + "\"}");

%>

Next we will introduce three methods of avatar upload (SWFUpload) (asp.net) and three (jquery plugin)

SWFUpload is a client file upload tool, initially created by Vinterwebb. se development, which integrates Flash and JavaScript technologies to provide WEB developers with a rich array of functions and then a file upload mode that surpasses the traditional <input type = "file"/> label. Another Flash plug-in is easy to use. It supports taking photos and uploading files from local cameras,
For more information about SWFUpload, see the Chinese translation documents of SWFUpload2.5 in Baidu encyclopedia and in the blog.
Http://www.cnblogs.com/youring2/archive/2012/07/13/2590010.html
SWFUpload. Net installation package and official Demo:
Http://download.csdn.net/detail/qq14039056961/5246596
You can learn about these two plug-ins through the above URL.


(Aspnet) create a widget that uploads an avatar and cut a small avatar like kaixin.com or renrenren.com.

Flash or Flex is enough.
Simple asp.net implementation is not very good

Source code for uploading an aspnet flash Avatar

A large number of ASP source codes are shared.
--------------------
: Move the cursor over my User Name
--------------------
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.