图片上传界面优化

选择图片 html代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link type="text/css" rel="Stylesheet" href="css/StyleSheet.css" />
    <link type="text/css" rel="Stylesheet" href="css/divRound.css" />

    <script type="text/javascript" src="js/JScript.js"></script>

    <script type="text/javascript" language="javascript">
    $(document).ready(function(){
    //选择图片事件
    $("#addfile").click(function(){
        $("#FileUpload1").click();    

    });

    //上传按钮事件
    $("#upload").click(function(){
        $("#btn_upload").click();
    });   

    });   

    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table>
            <tr>
                <td style="vertical-align: top; width: 10%;">
                    <asp:Image ID="Image1" ImageUrl="~/images/null.gif" Width="150px" Height="150px"
                        runat="server" />
                </td>
                <td>
                    <asp:FileUpload ID="FileUpload1" runat="server" ForeColor="#fff" Width="1px" Height="1px"
                        Visible="true" />
                    <a href="#">
                        <div class="loadfile" id="addfile">
                            选择图片
                        </div>
                    </a><a href="#">
                        <div class="loadfile" id="upload">
                            确定上传
                        </div>
                    </a>
                    <asp:Button ID="btn_upload" runat="server" Text="上传" CssClass="btnUpload" OnClick="btn_Onclick"
                        Width="1px" Height="1px" />
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <iframe src="Default.aspx" width="100%" height="300px" frameborder="0"></iframe>
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td>
                    <div style="position: relative; float: right;">
                        <asp:Button ID="btn_ok" runat="server" Text="确定" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:Button
                            ID="btn_no" runat="server" Text="取消" />
                    </div>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

后台代码:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;
using System.Xml.Linq;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            var ctrl = Request.Params[Page.postEventSourceID];
            var args = Request.Params[Page.postEventArgumentID];

            OnchangeHandle(ctrl, args);
        }
    }

    /// <summary>
    /// 绑定文件选择变更事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Init(object sender, EventArgs e)
    {
        this.FileUpload1.Attributes.Add("onchange", Page.ClientScript.GetPostBackEventReference(this.FileUpload1, "onchange"));
    }

    /// <summary>
    /// 文件选择变更事件
    /// </summary>
    /// <param name="ctrl"></param>
    /// <param name="args"></param>
    private void OnchangeHandle(string ctrl, string args)
    {
        if (this.FileUpload1.HasFile)
        {
            string photoName1 = this.FileUpload1.FileName; //获取初始文件名
            int i = photoName1.LastIndexOf("."); //取得文件名中最后一个"."的索引
            string newext = photoName1.Substring(i).ToLower(); //获取文件扩展名
            if (newext != ".gif" && newext != ".jpg" && newext != ".jpeg" && newext != ".bmp" && newext != ".png")
            {

                //第一种
                Response.Write("<script language=javascript>alert(‘抱歉,图片格式不正确,请重新选择!‘);</" + "script>");

            }
            else
            {
                if (ctrl == this.FileUpload1.UniqueID && args == "onchange")
                {
                    this.Image1.Visible = true;

                    Session["UploadBytes"] = this.FileUpload1.FileBytes;

                    this.Image1.ImageUrl = "~/Class1.axd";

                }
            }
        }
    }

    /// <summary>
    /// 上传按钮事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_Onclick(object sender, EventArgs e)
    {
        //建立存储的目录
        string directory = "Myfiles/";

        //判断目录是否存在
        if (!Directory.Exists(Server.MapPath(directory)))
        {
            //如果不存在,创建它
            Directory.CreateDirectory(Server.MapPath(directory));
        }

        //新文件
        string newFile = Server.MapPath(directory + Guid.NewGuid().ToString() + ".jpg");

        if ((Session["UploadBytes"]) != null)
        {
            byte[] buffer = (byte[])(Session["UploadBytes"]);

            File.WriteAllBytes(newFile, buffer);
        }
        if (Session["ImgList"] != null)
        {
            string tempStr = Session["ImgList"].ToString();
            tempStr += newFile + ";";
            Session["ImgList"] = tempStr;
        }
        else
        {
            Session["ImgList"] = newFile+";";
        }
    }

}

图片展示 前台代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
    <link type="text/css" rel="Stylesheet" href="css/StyleSheet.css" />
</head>
<body>
    <form id="form1" runat="server">
    <div class="container">
        <% if (imgStr != null)
           {
               for (int i = 0; i < imgStr.Length; i++)
               { %>
        <div class="imgItem">
            <div class="imgView_img">
                <asp:Image ID="img" runat="server" Width="100%" Height="100%" BorderStyle="None"
                    BorderWidth="0" ImageUrl="<%imgStr[i] %>" />
            </div>
            <div>
                <asp:RadioButton ID="rdoBtn" runat="server" GroupName="rdo" Text="封面" CssClass="imgView_btn" /><asp:LinkButton
                    CssClass="imgView_btn" runat="server" ID="likBtn" Text="删除"></asp:LinkButton></div>
        </div>
        <%}
           } %>
    </div>
    </form>
</body>
</html>

divRound.css:

.raised{background:transparent;width:150px;}
.raised h1,.raised p{margin:0 10px;}
.raised h1{font-size:30px;color:#fff; text-align:center}
.raised p{padding-bottom:0.5em;}
.raised .b1,.raised .b2,.raised .b3,.raised .b4,.raised .b1b,.raised .b2b,.raised .b3b,.raised .b4b{display:block;overflow:hidden;font-size:1px;}
.raised .b1,.raised .b2,.raised .b3,.raised .b1b,.raised .b2b,.raised .b3b{height:1px;}
.raised .b2{background:#f60;border-left:1px solid #fff;border-right:1px solid #eee;}
.raised .b3{background:#f60;border-left:1px solid #fff;border-right:1px solid #ddd;}
.raised .b4{background:#f60;border-left:1px solid #fff;border-right:1px solid #aaa;}
.raised .b4b{background:#f60;border-left:1px solid #eee;border-right:1px solid #999;}
.raised .b3b{background:#f60;border-left:1px solid #ddd;border-right:1px solid #999;}
.raised .b2b{background:#f60;border-left:1px solid #aaa;border-right:1px solid #999;}
.raised .b1{margin:0 5px;background:#fff;}
.raised .b2, .raised .b2b{margin:0 3px;border-width:0 2px;}
.raised .b3, .raised .b3b{margin:0 2px;}
.raised .b4, .raised .b4b{height:2px; margin:0 1px;}
.raised .b1b{margin:0 5px; background:#999;}
.raised .boxcontent{display:block;background:#f60;border-left:1px solid #fff;border-right:1px solid #999;}

/** 实例

<div class="raised">
<b class="b1"></b><b class="b2"></b><b class="b3"></b><b class="b4"></b>
<div class="boxcontent">
<h1>3D圆角矩形</h1>
</div>
<b class="b4b"></b><b class="b3b"></b><b class="b2b"></b><b class="b1b"></b>
</div>

**/

StyleSheet.css

body
{
}
.loadfile
{
    background-color: #f60;
    width: 100px;
    position: relative;
    float: left;
    margin-left: 40px;
    height: 40px;
    line-height: 40px;
    top: 50px;
    color: #fff;
    font-size: 20px;
    font-family: Microsoft YaHei;
    text-align: center;
    filter: progid:DXImageTransform.Microsoft.Shadow(color=#909090,direction=120,strength=4); /*ie*/
    -moz-box-shadow: 2px 2px 10px #909090; /*firefox*/
    -webkit-box-shadow: 2px 2px 10px #909090; /*safari或chrome*/
    box-shadow: 2px 2px 10px #909090; /*opera或ie9*/
}
.btnUpload
{
    position: absolute;
    top: -10px;
}
.divshadow
{

}

.container
{
    background-color: #333;
}
.imgView_btn
{
    position: relative;
    float: left;
    margin-left: 20px;
    font-size: 15px;
    margin-top: 5px;
}
.imgView_img
{
 border:0px;
}
.imgItem
{
    width: 150px;
    height: 180px;
    margin-left: 20px;
    margin-top:20px;
    position: relative;
    float: left;
    filter: progid:DXImageTransform.Microsoft.Shadow(color=#000,direction=120,strength=4); /*ie*/
    -moz-box-shadow: 2px 2px 10px #000; /*firefox*/
    -webkit-box-shadow: 2px 2px 10px #000; /*safari或chrome*/
    box-shadow: 2px 2px 10px #000; /*opera或ie9*/
}
时间: 2024-08-28 03:26:49

图片上传界面优化的相关文章

ckeditor4.5.1配置图片上传的方法

本篇博文主要面向初学者,一步一步地实现ckeditor的图片上传,欢迎各位大神指正. ckeditor的图片上传默认是关闭的,网上也有很多相关的教程,可是不是讲的不完整,就是版本太旧已经不适用.我写这篇博文主要面向初学者,有错误的地方欢迎指正. 截止本文撰写,ckeditor最新版本是4.5.1,我下载的版本是4.5.1standard,如果本文的方法不管用,请下载同一版本尝试. 1.开启图片上传界面 文件地址:ckeditor/plugins/image/dialogs/image.js 搜索

优化篇-“移动端”图片上传架构的变迁

做互联网应用少不了图片的支撑,图片的上传.浏览速度很大程度上决定着用户的体验,甚至用户去留,就因为其重要,所以,在任何时候,图片的架构和优化都在进行,不敢丝毫放松. 在以后几个章节,会从后端图片存储.前端浏览.动态浏览这些方面和大家分享一下我们一路过来的经验. 经过数据的观察,APP.WAP的用户量基本与PC端持平甚至超越,因此,应移动端用户体验和访问速度都被运营方盯得紧紧.在2014年的时候已经看到这个趋势后,主动监测发现移动端的跨运营商访问速度和稳定性真不敢恭维.所以,在那个时候开始,我们已

微信朋友圈的图片上传,多图上传怎么去撸才合适?我们一起来实现吧!

微信朋友圈的图片上传,多图上传怎么去撸才合适?我们一起来实现吧! 图片上传是非常常见的功能,而多图上传在大多数应用中也是非常常见的,比如微信的朋友圈,微博的动态,都是有九宫格图片的,那这里肯定涉及了多图上传,所以今天我们来一起撸一下,怎么去思考这个实现逻辑! 这里我想到的思路是比较简单的,首先,我们有一个按钮,按钮是上传图片,点击之后弹出某个界面进行图片的选择,一般是九张图片或者十二张,选完之后就直接上传了,大致的流程应该是这个样子,那我们首先来写个按钮 activity_main.xml <?

图片上传那些事

简述: 一个项目上,之前已经做好了用flash上传图片的功能,但是现在因为客户端的限制,要求不用flash,可以使用html5,于是改造开始了. 先给出之前flash的界面: 需求:  上面的图片里面可以看出三个需求: 1. 文件选择按钮外观需要美化 2. 可以预览图片 3. 上传图片(上传后的图片存在形式需要与之前flash上传的一样,也就是说需要byte[]的形式) 用户上传图片之后,需要把新的图片显示到其他位置,所以还有一个需求: 4. 上传成功后调用回调函数 思考: 1. 文件选择按钮外

CKEditor图片上传实现详细步骤(使用Struts 2)

本人使用的CKEditor版本是3.6.3.CKEditor配置和部署我就不多说. CKEditor的编辑器工具栏中有一项"图片域",该工具可以贴上图片地址来在文本编辑器中加入图片,但是没有图片上传. "预览"中有一大堆鸟语,看得很不爽.可以打开ckeditor/plugins/image/dialogs/image.js文件,搜索"b.config.image_previewText"就能找到这段鸟语了,(b.config.image_prev

项目整合ckeditor实现图片上传到远程服务器

最近手头上的一个Java项目需要做一个门户网站,其中有一个模块就是用来发布最新的业界安全动态的模块,因此需要用到后台发布新闻的功能:刚开始的时候在网上搜了一下,大部分都是关于PHP和.NET的,关于Java不多,而且查到的都是说用ckeditor+ckfinder来实现,ckeditor实现文本的编辑,ckfinder实现图片的上传,刚开始我也是准备用ckeditor+ckfinder来实现的,但是后来研究ckfinder的时候不知道如何配置ckfinder的图片上传路径问题,网上可以找到好多例

android选择图片或拍照图片上传到服务器(包括上传参数)

From:http://blog.csdn.net/springsky_/article/details/8213898具体上传代码: 1.选择图片和上传界面,包括上传完成和异常的回调监听 [java] view plaincopy package com.spring.sky.image.upload; import java.util.HashMap; import java.util.Map; import android.app.Activity; import android.app.

CKEditor不借助CKFinder实现图片上传(.net版 ashx实现)

参考博客:http://blog.csdn.net/mydwr/article/details/8669594 本人版本:4.4.6 打开文件:ckeditor/plugins/image/dialogs/image.js 搜索内容:[c.config.image_previewText],并删掉其后引号内的内容. 删除后格式:[c.config.image_previewText||""]. 与原文差异:原内容原文中是[b.config.image_previewText],我这里是

自学找工作【一】 任务:图片上传即时可见

工作已经快2周了,头儿给派了个任务做个企业站!这几天正在紧锣密鼓的作战中!等忙完了这个活!写下自己的学习心得体会!与看到文章的您一起分享! 在这里记录每次遇到的难题,如何解决的! 今天要做的功能就是实现上传图片即时可见! 效果如下: 下面说下大概思路,界面的话,会点儿CSS+DIV  HTML  百度一下都可以解决掉! 我这里写的有点儿稍微代码冗余了!因为就几张图片,懒的用for了! js方面:  添加图片之后,取得change的value,写到text中去!这个各个浏览器可能不一样,无所谓了!