标题:求图片上传的源码!!
只看楼主
雪夜白狼
Rank: 1
等 级:新手上路
帖 子:65
专家分:0
注 册:2008-3-24
 问题点数:0 回复次数:2 
求图片上传的源码!!
各位朋友谁有图片上传的代码啊
我自己写了一段可是调试老是出错?
有的话我学习一下啊!!
先谢谢了!!!
搜索更多相关主题的帖子: 图片上传 源码 代码 调试 朋友 
2008-04-30 21:20
beniao
Rank: 2
等 级:新手上路
威 望:4
帖 子:367
专家分:2
注 册:2004-12-17
得分:0 
回复 1# 的帖子
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;

public partial class UpImage_CheckFileType : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            if (FileUpload1.PostedFile.FileName == "")
            {
                this.lb_info.Text = "请选择文件!";
            }
            else
            {
                string filepath = FileUpload1.PostedFile.FileName;
                if (IsPicture(FileUpload1) == true)
                {
                    string filename = filepath.Substring(filepath.LastIndexOf("\\") + 1);
                    string SavaPath = Server.MapPath("UpLoad/") + filename;
                    FileUpload1.PostedFile.SaveAs(SavaPath);
                    this.lb_info.Text = "上传成功!";
                }
                else
                {
                    this.lb_info.Text = "请上传图片";
                }
            }
        }
        catch (Exception error)
        {
            this.lb_info.Text = "上传发生错误!原因:" + error.ToString();
        }


    }

    //定义实现验证上传图片的方法
    public static bool IsPicture(FileUpload hifile)
    {
        string strOldFilePath = "", strExtension = "";
        string[] arrExtension =   { ".gif", ".jpg", ".jpeg", ".bmp", ".png" };
        if (hifile.PostedFile.FileName != string.Empty)
        {
            strOldFilePath = hifile.PostedFile.FileName;
            strExtension = strOldFilePath.Substring(strOldFilePath.LastIndexOf("."));
            for (int i = 0; i < arrExtension.Length; i++)
            {
                if (strExtension.Equals(arrExtension[i]))
                {
                    return true;
                }
            }
        }
        return false;

    }
}

博客:http://
2008-05-01 16:44
雪夜白狼
Rank: 1
等 级:新手上路
帖 子:65
专家分:0
注 册:2008-3-24
得分:0 
谢谢啊
2008-05-09 16:47



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-211825-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.129920 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved