图片管理系统-源码
我急需一个ASP.Net图片(相册)管理系统,要求就是,能批量上传的,可以对图片修改删除,希望各位大神们,帮帮忙,十万火急!
[解决办法]
css:
.mflLeft
{
font-size:13px;
position:relative;
float:left;
clear:left;
margin:5px;
width:100px;
height:300px;
border:solid 1px silver;
text-align:center;
}
.mflRight
{
font-size:13px;
position:relative;
float:left;
width:300px;
height:300px;
margin:5px;
margin-left:0px;
border:solid 1px silver;
overflow:auto;
text-align:left;
}
.mflBottom
{
position:relative;
clear:both;
margin:0px 5px 0px 5px;
width:400px;
padding:4px;
text-align:left;
border:solid 1px silver;
}
/*******上传文件控件样式*******/
.mflFileUploadCss
{
width:70px;
height:30px;
margin:-2px 0px 0px -7px;
filter:alpha(opacity=0);
opacity:0;
}
/******包含上传控件的Div******/
.mflLeft_FileUpload
{
position:relative;
margin-top:30px;
border:solid 1px silver;
width:71px;
height:28px;
overflow:hidden;
clear:both;
cursor:pointer;
background-image:url("../images/view.gif");
background-repeat:no-repeat;
background-position:left center;
}
/****保存上传文件信息的OL样式****/
.mflRightOlFiles
{
margin-top:20px;
}
.mflRightOlFiles li
{
padding:5px;
}
span
{
font-size:12px;
color:green;
}
.mflFileCountMsg
{
margin-left:10px;
}
.FileNameStyle
{
color:Silver;
}
</style>
js:
<script type="text/javascript">
//限制文件数
var mflFileMaxCount = 5;
var mflFileCount = 0;
//限制文件类型
var mflCouldUserTypes = "|.jpeg|.jpg|.gif|.png|";
function AddFile(obj) {
var fileName = obj.value;
if (mflFileCount >= mflFileMaxCount) {
window.alert("信息提示:系统设置,最多只能同时上传[" + mflFileMaxCount + "]个文件.");
return;
}
if ($.trim(fileName) == "") {
//用户没有选择文件
return;
}
var type = fileName.substring(fileName.lastIndexOf("."));
type = type.toLowerCase();
var sFileName = fileName.substring(fileName.lastIndexOf("\\"));
var newFileLoadTmp = "<input type='file' name='mflFileUpload" + (mflFileCount + 1) + "' id='mflFileUpload" + (mflFileCount + 1) + "' onchange='AddFile(this)' class='mflFileUploadCss' />"
var newLiFile = "<li><span class='FileNameStyle'>" + sFileName + "</span> <img src='../images/ac_02.jpg' onclick='mflRemoveFile(this)' /></li>";
if ($.trim(type) == "" || $.trim(sFileName) == "") {
//用户没有选择文件
return;
}
if (mflCouldUserTypes.indexOf("|" + type + "|") != -1) {
$(obj).css("display", "none");
$(".mflLeft_FileUpload").append(newFileLoadTmp);
$(".mflRightOlFiles").append(newLiFile);
mflFileCount += 1;
$(".mflFileCountMsg").html("已选文件数:" + mflFileCount);
}
else {
window.alert("信息提示:文件类型不正确。");
}
}
function mflRemoveFile(obj) {
if (confirm("信息提示:确定移除该文件?")) {
var innerHtml = $(obj).parent().html();
var itemIndex = 0;
for (itemIndex = 0; itemIndex < $(".mflRightOlFiles li").length; itemIndex++) {
if ($(".mflRightOlFiles li").eq(itemIndex).html() == innerHtml) {
break;
}
}
$(".mflRightOlFiles li").eq(itemIndex).remove();
$(".mflLeft_FileUpload input").eq(itemIndex).remove();
mflFileCount -= 1;
$(".mflFileCountMsg").html("已选文件数:" + mflFileCount);
}
}
</script>
html:
<div class="mflLeft">
<div class="mflLeft_FileUpload" title="点击浏览图片">
<asp:FileUpload ID="mflFileUpload" onchange="AddFile(this)" CssClass="mflFileUploadCss"
runat="server" /></div>
</div>
<div class="mflRight">
<ol class="mflRightOlFiles">
</ol>
</div>
<div class="mflBottom">
<asp:Button ID="btnUpload" runat="server" Text="批量上传" OnClick="btnUpload_Click" />
<span>文件类型:jpeg ; jpg ; gif ; png</span>
<span class="mflFileCountMsg"></span>
</div>
cs:
const string mflCouldUserTypes = "|.jpeg|.jpg|.gif|.png|";
public string f;
PictureModel MPicture = new PictureModel();//自己的实体
PictureBLL BPicture = new PictureBLL();//方法
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.Cookies["LoginUserID"] == null)
{
Response.Redirect("../Login.aspx");
}
else
{
if (Request.QueryString["ActId"] == "")
{
Response.Redirect("PreviousCaboodleActivities.aspx");
}
}
}
}
protected void btnUpload_Click(object sender, EventArgs e)
{
if (Request.Files.Count > 0)
{
StringBuilder sbFileName = new StringBuilder();
for (int i = 0; i < Request.Files.Count; i++)
{
if (Request.Files[i].ContentLength > 0)
{
string fileType = Request.Files[i].FileName.Substring(Request.Files[i].FileName.LastIndexOf('.'));
if (mflCouldUserTypes.IndexOf(String.Format("|{0}|", fileType)) == -1)
{//上传了非设置的图片
continue;
}
string newFileName = DateTime.Now.ToString("yyyyMMddHHmmssms" + i) + fileType;
MPicture.PictureURL = "UpImage/" + newFileName;
Request.Files[i].SaveAs(Server.MapPath("../UpImage/" + newFileName));
MPicture.ActId = Request.QueryString["ActId"];
MPicture.AddTime = DateTime.Now;
MPicture.PictureId = AdminLibrary.CommonFunction.GetTableIdentity("PictureId", "PictureTB");
BPicture.Add(MPicture);
}
}
Page.RegisterStartupScript("msg", "<script>window.alert('信息提示:文件上传成功。');window.location.href=window.location.href;</script>");
}
}