房地产数据库中有个BLOB(IMAGE)字段,存储图片,用户查询户型的时候要看相应的户型图,怎么通过查询之后把图片放在页面上?
主要解决一个问题:对应记录的图片放在页面上!
主要解决一个问题:对应记录的图片放在页面上!
解决方案 »
- 有没有什么好的基于谷歌地图开发的点子呢
- 谁能给我解释这段代码啊,JS计算器的加减乘除,谢谢!!!!
- iframe刷新后并跳转页
- 这个能用3木写吗
- 第三方的div确认提示框为什么不能代替window.confirm()
- jquery.lazyload问题
- 怎样往<td></td>中添加属性
- JS 中的空格问题
- 请问播放media文件的时候能不能自定义大小? 谢了
- 我要类似 http://jqueryui.com/tabs/#sortable 他时标签 能调整顺序 但也能添加删除标签 修改
- ★★★★ 键盘控制表格问题 ★★★★
- 求JS代码:类似新浪搜狐等网站的广告,慢慢弹出一张非常大的图片,再自己缩小,直到不见了
<%@ Page language="c#" %>
<script language="C#" runat="server">// Messages
private string NoFileMessage = "没有文件被选择";
private string UploadSuccessMessage = "上传成功";
private string NoImagesMessage = "没有图片";
private string NoFolderSpecifiedMessage = "没有文件夹";
private string NoFileToDeleteMessage = "没有文件被删除";
private string InvalidFileTypeMessage = "不匹配的文件类型";
private string[] AcceptedFileTypes = new string[] {"jpg","jpeg","jpe","gif","bmp","png"};// Configuration
private bool UploadIsEnabled = true;
private bool DeleteIsEnabled = true;
private string DefaultImageFolder = "images";private void Page_Load(object sender, System.EventArgs e) {
string isframe = "" + Request["frame"];
if (isframe != "") {
MainPage.Visible = true;
iframePanel.Visible = false;
string rif = "" + Request["rif"];
string cif = "" + Request["cif"]; // Response.Write("<s" + "cript>confirm('" + rif + "');</s" + "cript>");
if (cif != "" && rif != "") {
RootImagesFolder.Value = rif;
CurrentImagesFolder.Value = cif;
} else {
RootImagesFolder.Value = DefaultImageFolder;
CurrentImagesFolder.Value = DefaultImageFolder;
} UploadPanel.Visible = UploadIsEnabled;
DeleteImage.Visible = DeleteIsEnabled; string FileErrorMessage = "";
string ValidationString = ".*(";
//[\.jpg]|[\.jpeg]|[\.jpe]|[\.gif]|[\.bmp]|[\.png])$"
for (int i=0;i<AcceptedFileTypes.Length; i++) {
ValidationString += "[\\." + AcceptedFileTypes[i] + "]";
if (i < (AcceptedFileTypes.Length-1)) ValidationString += "|";
FileErrorMessage += AcceptedFileTypes[i];
if (i < (AcceptedFileTypes.Length-1)) FileErrorMessage += ", ";
}
FileValidator.ValidationExpression = ValidationString+")$";
FileValidator.ErrorMessage=FileErrorMessage; if (!IsPostBack) {
DisplayImages();
}
} else {
}
}public void CreateFolder_OnClick(object sender, EventArgs e)
{
if(CreateFolder.Value != "")
{
string UploadFileDestination = "";
UploadFileDestination = HttpContext.Current.Request.PhysicalApplicationPath;
UploadFileDestination += CurrentImagesFolder.Value;
UploadFileDestination += "\\" + CreateFolder.Value;
System.IO.Directory.CreateDirectory(UploadFileDestination);
}else
{
// errInfo.InnerHtml = "必须先输入要新建的文件夹名称!";
}
DisplayImages();
}public void UploadImage_OnClick(object sender, EventArgs e) {
if (Page.IsValid) {
if (CurrentImagesFolder.Value != "") {
if (UploadFile.PostedFile.FileName.Trim() != "") {
if (IsValidFileType(UploadFile.PostedFile.FileName)) {
try {
string UploadFileName = "";
string UploadFileDestination = "";
UploadFileName = UploadFile.PostedFile.FileName;
UploadFileName = UploadFileName.Substring(UploadFileName.LastIndexOf("\\")+1);
UploadFileDestination = HttpContext.Current.Request.PhysicalApplicationPath;
UploadFileDestination += CurrentImagesFolder.Value;
UploadFileDestination += "\\";
UploadFile.PostedFile.SaveAs(UploadFileDestination + UploadFileName);
ResultsMessage.Text = UploadSuccessMessage;
System.Drawing.Image myImage = System.Drawing.Image.FromFile(UploadFileDestination + UploadFileName); int ImgWidth, ImgHeight;
if(myImage.Width <= 400)
{
ImgWidth = myImage.Width;
ImgHeight = myImage.Height;
}else{
ImgWidth = 400;
ImgHeight = ImgWidth * myImage.Height / myImage.Width;
}
myImage.Dispose();
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
string AppPath = HttpContext.Current.Request.PhysicalApplicationPath;
string AppUrl;
//Get the application's URL
if (Request.ApplicationPath == "/")
AppUrl = Request.ApplicationPath;
else
AppUrl = Request.ApplicationPath + "/";
string ImageFileLocation = AppUrl;
ImageFileLocation = ImageFileLocation.Substring(ImageFileLocation.LastIndexOf("\\")+1);
//galleryfilelocation += "/";
ImageFileLocation += CurrentImagesFolder.Value;
ImageFileLocation += "/";
Response.Write(
"<s" + "cript>"+
"var YN = confirm('是否现在插入?'); " +
"if(YN == true){" +
"var arr = new Array();" +
"arr['filename'] = '" + (ImageFileLocation + UploadFileName).Replace("\\","/") +
"';arr['width'] =" + ImgWidth.ToString() +
";arr['height'] = " + ImgHeight.ToString() +
";window.parent.returnValue = arr;window.parent.close();}" +
"</s" + "cript>");
} catch(Exception ex) {
//ResultsMessage.Text = "Your file could not be uploaded: " + ex.Message;
ResultsMessage.Text = "上传时产生错误!";
}
} else {
ResultsMessage.Text = InvalidFileTypeMessage;
}
} else {
ResultsMessage.Text = NoFileMessage;
}
} else {
ResultsMessage.Text = NoFolderSpecifiedMessage;
}
} else {
ResultsMessage.Text = InvalidFileTypeMessage;
}
DisplayImages();
}public void DeleteImage_OnClick(object sender, EventArgs e) {
if (FileToDelete.Value != "" && FileToDelete.Value != "undefined") {
try {
string AppPath = HttpContext.Current.Request.PhysicalApplicationPath;
System.IO.File.Delete(AppPath + CurrentImagesFolder.Value + "\\" + FileToDelete.Value);
ResultsMessage.Text = "删除: " + FileToDelete.Value;
} catch(Exception ex) {
ResultsMessage.Text = "删除时产生错误!";
}
} else {
ResultsMessage.Text = NoFileToDeleteMessage;
}
DisplayImages();
}private bool IsValidFileType(string FileName) {
string ext = FileName.Substring(FileName.LastIndexOf(".")+1,FileName.Length-FileName.LastIndexOf(".")-1);
for (int i=0; i<AcceptedFileTypes.Length; i++) {
if (ext == AcceptedFileTypes[i]) {
return true;
}
}
return false;
}
private string[] ReturnFilesArray() {
if (CurrentImagesFolder.Value != "") {
try {
string AppPath = HttpContext.Current.Request.PhysicalApplicationPath;
string ImageFolderPath = AppPath + CurrentImagesFolder.Value;
string[] FilesArray = System.IO.Directory.GetFiles(ImageFolderPath,"*");
return FilesArray;
} catch {
return null;
}
} else {
return null;
}}private string[] ReturnDirectoriesArray() {
if (CurrentImagesFolder.Value != "") {
try {
string AppPath = HttpContext.Current.Request.PhysicalApplicationPath;
string CurrentFolderPath = AppPath + CurrentImagesFolder.Value;
string[] DirectoriesArray = System.IO.Directory.GetDirectories(CurrentFolderPath,"*");
return DirectoriesArray ;
} catch {
return null;
}
} else {
return null;
}
}
string[] FilesArray = ReturnFilesArray();
string[] DirectoriesArray = ReturnDirectoriesArray();
string AppPath = HttpContext.Current.Request.PhysicalApplicationPath;
string AppUrl;
//Get the application's URL
if (Request.ApplicationPath == "/")
AppUrl = Request.ApplicationPath;
else
AppUrl = Request.ApplicationPath + "/";
GalleryPanel.Controls.Clear();
if ( (FilesArray == null || FilesArray.Length == 0) && (DirectoriesArray == null || DirectoriesArray.Length == 0) ) {
gallerymessage.Text = NoImagesMessage + ": " + RootImagesFolder.Value;
} else {
string ImageFileName = "";
string ImageFileLocation = ""; int thumbWidth = 94;
int thumbHeight = 94;
if (CurrentImagesFolder.Value != RootImagesFolder.Value) { System.Web.UI.HtmlControls.HtmlImage myHtmlImage = new System.Web.UI.HtmlControls.HtmlImage();
myHtmlImage.Src = AppUrl + "images/ftb/folder.up.gif";
myHtmlImage.Attributes["unselectable"]="on";
myHtmlImage.Attributes["align"]="absmiddle";
myHtmlImage.Attributes["vspace"]="36"; string ParentFolder = CurrentImagesFolder.Value.Substring(0,CurrentImagesFolder.Value.LastIndexOf("\\")); System.Web.UI.WebControls.Panel myImageHolder = new System.Web.UI.WebControls.Panel();
myImageHolder.CssClass = "imageholder";
myImageHolder.Attributes["unselectable"]="on";
myImageHolder.Attributes["onclick"]="divClick(this,'');";
myImageHolder.Attributes["ondblclick"]="gotoFolder('" + RootImagesFolder.Value + "','" + ParentFolder.Replace("\\","\\\\") + "');";
myImageHolder.Controls.Add(myHtmlImage); System.Web.UI.WebControls.Panel myMainHolder = new System.Web.UI.WebControls.Panel();
myMainHolder.CssClass = "imagespacer";
myMainHolder.Controls.Add(myImageHolder); System.Web.UI.WebControls.Panel myTitleHolder = new System.Web.UI.WebControls.Panel();
myTitleHolder.CssClass = "titleHolder";
myTitleHolder.Controls.Add(new LiteralControl("上一级"));
myMainHolder.Controls.Add(myTitleHolder); GalleryPanel.Controls.Add(myMainHolder);
}
foreach (string _Directory in DirectoriesArray) {
try {
string DirectoryName = _Directory.ToString();
System.Web.UI.HtmlControls.HtmlImage myHtmlImage = new System.Web.UI.HtmlControls.HtmlImage();
myHtmlImage.Src = AppUrl + "images/ftb/folder.big.gif";
myHtmlImage.Attributes["unselectable"]="on";
myHtmlImage.Attributes["align"]="absmiddle";
myHtmlImage.Attributes["vspace"]="29"; System.Web.UI.WebControls.Panel myImageHolder = new System.Web.UI.WebControls.Panel();
myImageHolder.CssClass = "imageholder";
myImageHolder.Attributes["unselectable"]="on";
myImageHolder.Attributes["onclick"]="divClick(this);";
myImageHolder.Attributes["ondblclick"]="gotoFolder('" + RootImagesFolder.Value + "','" + DirectoryName.Replace(AppPath,"").Replace("\\","\\\\") + "');";
myImageHolder.Controls.Add(myHtmlImage); System.Web.UI.WebControls.Panel myMainHolder = new System.Web.UI.WebControls.Panel();
myMainHolder.CssClass = "imagespacer";
myMainHolder.Controls.Add(myImageHolder); System.Web.UI.WebControls.Panel myTitleHolder = new System.Web.UI.WebControls.Panel();
myTitleHolder.CssClass = "titleHolder";
myTitleHolder.Controls.Add(new LiteralControl(DirectoryName.Replace(AppPath + CurrentImagesFolder.Value + "\\","")));
myMainHolder.Controls.Add(myTitleHolder); GalleryPanel.Controls.Add(myMainHolder);
} catch {
// nothing for error
}
}
foreach (string ImageFile in FilesArray) { try { ImageFileName = ImageFile.ToString();
ImageFileName = ImageFileName.Substring(ImageFileName.LastIndexOf("\\")+1);
ImageFileLocation = AppUrl;
ImageFileLocation = ImageFileLocation.Substring(ImageFileLocation.LastIndexOf("\\")+1);
//galleryfilelocation += "/";
ImageFileLocation += CurrentImagesFolder.Value;
ImageFileLocation += "/";
ImageFileLocation += ImageFileName;
System.Web.UI.HtmlControls.HtmlImage myHtmlImage = new System.Web.UI.HtmlControls.HtmlImage();
myHtmlImage.Src = ImageFileLocation;
System.Drawing.Image myImage = System.Drawing.Image.FromFile(ImageFile.ToString());
myHtmlImage.Attributes["unselectable"]="on";
//myHtmlImage.border=0; // landscape image
if (myImage.Width > myImage.Height) {
if (myImage.Width > thumbWidth) {
myHtmlImage.Width = thumbWidth;
myHtmlImage.Height = Convert.ToInt32(myImage.Height * thumbWidth/myImage.Width);
} else {
myHtmlImage.Width = myImage.Width;
myHtmlImage.Height = myImage.Height;
}
// portrait image
} else {
if (myImage.Height > thumbHeight) {
myHtmlImage.Height = thumbHeight;
myHtmlImage.Width = Convert.ToInt32(myImage.Width * thumbHeight/myImage.Height);
} else {
myHtmlImage.Width = myImage.Width;
myHtmlImage.Height = myImage.Height;
}
}
if (myHtmlImage.Height < thumbHeight) {
myHtmlImage.Attributes["vspace"] = Convert.ToInt32((thumbHeight/2)-(myHtmlImage.Height/2)).ToString();
}
System.Web.UI.WebControls.Panel myImageHolder = new System.Web.UI.WebControls.Panel();
myImageHolder.CssClass = "imageholder";
myImageHolder.Attributes["onclick"]="divClick(this,'" + ImageFileName + "');";
int ImgWidth, ImgHeight;
if(myImage.Width <= 400)
{
ImgWidth = myImage.Width;
ImgHeight = myImage.Height;
}else{
ImgWidth = 400;
ImgHeight = ImgWidth * myImage.Height / myImage.Width;
}
myImageHolder.Attributes["ondblclick"]="returnImage('" + ImageFileLocation.Replace("\\","/") + "','" + ImgWidth.ToString() + "','" + ImgHeight.ToString() + "');";
myImageHolder.Controls.Add(myHtmlImage);
System.Web.UI.WebControls.Panel myMainHolder = new System.Web.UI.WebControls.Panel();
myMainHolder.CssClass = "imagespacer";
myMainHolder.Controls.Add(myImageHolder); System.Web.UI.WebControls.Panel myTitleHolder = new System.Web.UI.WebControls.Panel();
myTitleHolder.CssClass = "titleHolder";
myTitleHolder.Controls.Add(new LiteralControl(ImageFileName + "<BR>" + myImage.Width.ToString() + "x" + myImage.Height.ToString()));
myMainHolder.Controls.Add(myTitleHolder); //GalleryPanel.Controls.Add(myImage);
GalleryPanel.Controls.Add(myMainHolder);
myImage.Dispose();
} catch { }
}
gallerymessage.Text = "";
}
}
<asp:panel id="MainPage" runat="server" visible="false">
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<META HTTP-EQUIV="Expires" CONTENT="0">
<title>Insert Image</title>
<style>body {
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
background: #ffffff;
width: 100%;
overflow:hidden;
border: 0;
}body,tr,td {
color: #000000;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10pt;
}div.imagespacer {
width: 120;
height: 126;
text-align: center;
float: left;
font: 10pt verdana;
margin: 5px;
overflow: hidden;
}
div.imageholder {
margin: 0px;
padding: 0px;
border: 1 solid #CCCCCC;
width: 100;
height: 100;
}div.titleholder {
font-family: ms sans serif, arial;
font-size: 8pt;
width: 100;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
} </style><script language="javascript">
lastDiv = null;
function divClick(theDiv,filename) {
if (lastDiv) {
lastDiv.style.border = "1 solid #CCCCCC";
}
lastDiv = theDiv;
theDiv.style.border = "2 solid #316AC5";
document.getElementById("FileToDelete").value = filename;}
function gotoFolder(rootfolder,newfolder) {
window.navigate("ftb.imagegallery.aspx?frame=1&rif=" + rootfolder + "&cif=" + newfolder);
}
function returnImage(imagename,width,height) {
var arr = new Array();
arr["filename"] = imagename;
arr["width"] = width;
arr["height"] = height;
window.parent.returnValue = arr;
window.parent.close();
}
</script>
</HEAD>
<body>
<table width=100% height=100% cellpadding=0 cellspacing=0 border=0><FORM encType="multipart/form-data" runat="server">
<asp:Panel id="UploadPanel" runat="server">
<tr><td height=16 style="padding-left:10px;border-top: 1 solid #999999; background-color:#99CCFF;">
<table>
<tr>
<td valign=top>新建文件夹:<input id="CreateFolder" type="text" name="CreateFolder" runat="server" style="width:150;" title="在此输入要新建的文件夹名称。" />
<asp:button id="butCreateFolder" Text="新建" runat="server" onclick="CreateFolder_OnClick" title="新建文件夹。"/></td>
<!-- <td><DIV id="errInfo" name="errInfo" runat="server" style="DISPLAY: inline; WIDTH: 70px; HEIGHT: 15px" ms_positioning="FlowLayout">Label</DIV>
</td> -->
</tr>
<tr>
<td valign=top>上传图片:  <input id="UploadFile" type="file" name="UploadFile" runat="server" style="width:300;"/></td>
<td valign=top><asp:button id="UploadImage" Text="上传" runat="server" onclick="UploadImage_OnClick"/></td>
<td valign=top><asp:button id="DeleteImage" Text="删除" runat="server" onclick="DeleteImage_OnClick"/></td>
<td valign=middle>
</tr>
<tr>
<td colspan=3>
<asp:RegularExpressionValidator runat="server"
ControlToValidate="UploadFile"
id="FileValidator" display="dynamic"/>
<asp:literal id="ResultsMessage" runat="server" />
</td>
</tr></table>
<input type="hidden" id="FileToDelete" Value="" runat="server" />
<input type="hidden" id="RootImagesFolder" Value="images" runat="server" />
<input type="hidden" id="CurrentImagesFolder" Value="images" runat="server" />
</td></tr>
</asp:panel>
<tr><td>
<div id="galleryarea" style="width=100%; height:100%; overflow: auto;">
<asp:label id="gallerymessage" runat="server"></asp:label>
<asp:panel id="GalleryPanel" runat="server"></asp:panel>
</div>
</td></tr></form>
</table>
</body>
</HTML>
</asp:panel>
<asp:panel id="iframePanel" runat="server" >
<html>
<head><title>插入图片</title></head>
<style>
body {
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
background: #ffffff;
overflow:hidden;
}
</style>
<body>
<iframe style="width:100%;height:100%;border:0;" border=0 frameborder=0 src="ftb.imagegallery.aspx?frame=1&<%=Request.QueryString%>"></iframe>
</body>
</html>
</asp:panel>