免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
Asp.net實(shí)現(xiàn)多圖片上傳
前臺(tái)代碼----》
 
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FileUp.aspx.cs" Inherits="FileUp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head id="Head1" runat="server">
<title>ASP.NET(C#)實(shí)現(xiàn)一次性上傳多張圖片</title>
<script type="text/javascript">
var i=1;
function addFile()
{
    if (i<10)
    {
        var str = '<BR> <input type="file" name="File" runat="server" style="width: 200px"/>描述:<input name="text" type="text" style="width: 150px" maxlength="20" />';
        document.getElementById('MyFile').insertAdjacentHTML("beforeEnd",str);
    }
    else
    {
        alert("您一次最多只能上傳10張圖片!");
    }
    i++;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table id="Table1" align="center" border="0" cellpadding="1" cellspacing="1" class="table">
    <tr>
        <td align="center"><font color="#0000ff" face="宋體" size="3"><strong>上傳圖片</strong></font></td>
    </tr>
    <tr>
        <td align="center" style="width: 734px"></td>
    </tr>
    <tr>
        <td align="center" style="width: 734px">
        <asp:Panel ID="Panel5" runat="server">
        <table width="100%">
            <tr>
                <td align="right" style="width: 100px"></td>
                <td align="left" style="width: 500px">說明:點(diǎn)增加圖片按鈕可一次上傳多張圖片,可為每張圖片寫上一句不超過20個(gè)字的描述。單張圖片大小不大于1024k</td>
            </tr>
            <tr>
                <td align="right" style="width: 100px">請選擇圖片:<br /></td>
                <td align="left" style="width: 500px"><p id="MyFile"><input onclick="addFile()" type="button" value="增加圖片(Add)"></p><br /><input id="File1" type="file" name="File" runat="server" style="width: 245px"/>描述:<input name="text" type="text" style="width: 150px" maxlength="20" /></td>
            </tr>
            <tr>
                <td align="right" style="width: 100px"></td>
                <td align="left" style="width: 500px"><asp:Button ID="btnUpload" runat="server" Text="開始上傳" OnClick="btnUpload_Click"  /></td>
            </tr>
            <tr>
                <td align="right" style="width: 100px"></td>
                <td align="left" style="width: 500px"><asp:Label ID="lblMessage" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label></td>
            </tr>
        </table>
        </asp:Panel>
        </td>
    </tr>
    <tr>
        <td align="center" style="width: 734px"></td>
    </tr>
</table>
</div>
</form>
</body>
</html>
public partial class FileUp : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        lblMessage.Text = "";
        lblMessage.Visible = false;
        System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
        System.Text.StringBuilder strmsg = new System.Text.StringBuilder("");
        string[] rd = Request.Form[1].Split(',');//獲得圖片描述的文本框字符串?dāng)?shù)組,為對應(yīng)的圖片的描述
        //string albumid=ddlAlbum.SelectedValue.Trim();
        int ifile;
        for (ifile = 0; ifile < files.Count; ifile++)
        {
            if (files[ifile].FileName.Length > 0)
            {
                System.Web.HttpPostedFile postedfile = files[ifile];
                if (postedfile.ContentLength / 1024 > 1024)//單個(gè)文件不能大于1024k
                {
                    strmsg.Append(Path.GetFileName(postedfile.FileName) + "---不能大于1024k<br>");
                    break;
                }
                string fex = Path.GetExtension(postedfile.FileName);
                if (fex != ".jpg" && fex != ".JPG" && fex != ".gif" && fex != ".GIF"&& fex !=".png"&& fex !=".PNG")
                {
                    strmsg.Append(Path.GetFileName(postedfile.FileName) + "---圖片格式不對,只能是jpg或gif或png<br>");
                    break;
                }
            }
        }
        if (strmsg.Length <= 0)    //說明圖片大小和格式都沒問題
        {
            //以下為創(chuàng)建圖庫目錄
            string dirpath = Server.MapPath("photo");
            if (Directory.Exists(dirpath) == false)
            {
                Directory.CreateDirectory(dirpath);
            }
            Random ro = new Random();
            int name = 1;
            for (int i = 0; i < files.Count; i++)
            {
                System.Web.HttpPostedFile myFile = files[i];
                string FileName = "";
                string FileExtention = "";
                FileName = System.IO.Path.GetFileName(myFile.FileName);
                string stro = ro.Next(100, 100000000).ToString() + name.ToString();//產(chǎn)生一個(gè)隨機(jī)數(shù)用于新命名的圖片
                string NewName = DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + stro;
                if (FileName.Length > 0)//有文件才執(zhí)行上傳操作再保存到數(shù)據(jù)庫
                {
                    FileExtention = System.IO.Path.GetExtension(myFile.FileName);
                    string ppath = dirpath + @"/" + NewName + FileExtention;
                    myFile.SaveAs(ppath);
                }
                name = name + 1;//用來重命名規(guī)則的變量
            }
            Response.Write("<script>alert('恭喜,圖片上傳成功!')</script>");
        }
        else
        {
            lblMessage.Text = strmsg.ToString();
            lblMessage.Visible = true;
        }
    }
}
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
無組件上傳圖片到數(shù)據(jù)庫中,最完整解決方案
網(wǎng)頁設(shè)計(jì)中當(dāng)前正在訪問的導(dǎo)航欄高亮顯示的解決方案
asp做問卷調(diào)查 投票
微星橫向菜單
天氣web service網(wǎng)站實(shí)例講解
透明動(dòng)態(tài)的相框
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服