using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.IO; using System.Text; public partial class Main : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { DirectoryInfo myDirInfo; myDirInfo = new DirectoryInfo(Server.MapPath("upload/")); FileInfo[] arrFileInfo = myDirInfo.GetFiles("*.*"); foreach (FileInfo myFileInfo in arrFileInfo) { HyperLink hyp = new HyperLink(); hyp.NavigateUrl = "Main.aspx?mov=" + myFileInfo.Name; hyp.Text = myFileInfo.Name; Literal lit = new Literal(); lit.Text = "<br />"; Panel1.Controls.Add(hyp); Panel1.Controls.Add(lit); } if (Request.QueryString["mov"] != null) { String src = "upload/" + Request.QueryString["mov"]; Literal1. Text = "<object classid='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6' id='Player1' style='width: 600px; height: 400px'><param name='URL' value='" + src + "'><param name='AutoStart' value='True'><param name='ShowControls' value='True'><param name='ShowStatusBar' value='True'><param name='ShowDisplay' value='True'><param name='AutoRewind' value='True'>" + "<embed type='application/x-mplayer2'" + "pluginspage='http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/'" + " width='352' height='352'" + " src='" + src + "'" + " autostart='False' showcontrols='True' showstatusbar='True' showdisplay='True' autorewind='True'></embed>" + "</object>"; } } protected void Button1_Click(object sender, EventArgs e) { } }
<%@ Page Language="C#" Debug="true" %> <%@ Import Namespace="System.Data"%> <%@ Import Namespace="System.Data.OleDb"%> <script runat="server"> void btnUpload_OnClick(Object sender, EventArgs e) { this.pnlUpload.Visible = false; this.pnlSave.Visible = true; if(!this.fiUpload.HasFile) { this.lblText.Text = "Please select upload file!"; } else { this.fiUpload.SaveAs(Server.MapPath("Myfiles/"+fiUpload.FileName)); this.lblText.Text = "<b>" + fiUpload.FileName + "</b> Uploaded.<br>"; //*** Save to Database ***// OleDbConnection objConn; OleDbCommand objCmd; String strConnString,strSQL; strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("database/mydatabase.mdb") + ";"; objConn = new OleDbConnection(strConnString); objConn.Open(); strSQL = "INSERT INTO picture (PictureName) " + "VALUES ('" + fiUpload.FileName + "')"; objCmd = new OleDbCommand(); objCmd.Connection = objConn; objCmd.CommandType = CommandType.Text; objCmd.CommandText = strSQL; objCmd.ExecuteNonQuery(); objCmd = null; objConn.Close(); objConn = null; this.hplLink1.NavigateUrl = "AspNetFileUploadToDatabase1.aspx"; this.hplLink2.NavigateUrl = "AspNetFileUploadToDatabase2.aspx"; } } </script> <html> <head> <title>ThaiCreate.Com ASP.NET - Upload files</title> </head> <body> <form id="form1" runat="server"> <asp:Panel id="pnlUpload" runat="server"> <asp:FileUpload id="fiUpload" runat="server"></asp:FileUpload> <input id="btnUpload" type="button" OnServerClick="btnUpload_OnClick" value="Upload" runat="server" /> </asp:Panel> <asp:Panel id="pnlSave" Visible="false" runat="server"> <asp:Label id="lblText" runat="server"></asp:Label><br /> <asp:HyperLink id="hplLink1" runat="server">Upload again</asp:HyperLink> , <asp:HyperLink id="hplLink2" runat="server">View files</asp:HyperLink> </asp:Panel> </form> </body> </html>
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง