请教:freetextbox1.63的上传图片不成功的问题。附代码

blureyes2003 2004-10-21 09:02:47
我用的是修改过的代码:
原来的上传图片功能是可以管理如upload目录里所有图片的功能
我现在修改后是只能上传图片,而不能看见upload目录里的其它图片
此功能在本地运行成功,但是程序上传到服务器上时,图片依然上传成功,根目录下upload目录里有上传的图片,但是freetextbox里显示出错误的图片,检查图片路径后发现路径为:http://upload/0410210903_253.gif
显然前面的:www.xxx.com掉了。。
请大家帮我看看下面的代码哪里有错误,导致了上面的问题。。


<%@ Page language="c#" %>
<script runat="server">

// Messages
private string NoFileMessage = "您没有选择文件。";
private string UploadSuccessMessage = "上传成功";
private string UploadFailureMessage = "上传失败。";
private string NoImagesMessage = "该文件夹不存在或者是空的";
private string NoFolderSpecifiedMessage = "您要上传到的文件夹不存在。";
private string NoFileToDeleteMessage = "您没有选中要删除的文件。";
private string InvalidFileTypeMessage = "您无法上传这种类型的文件。";
private string[] AcceptedFileTypes = new string[] {"jpg","jpeg","jpe","gif","JPG","JPEG","JPE","GIF"};

// Configuration
private bool UploadIsEnabled = true; // 是否允许上传文件
private bool DeleteIsEnabled = false; // 是否允许删除文件
private string DefaultImageFolder = "upload"; // 默认的起始文件夹

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"];

RootImagesFolder.Value = Server.MapPath(".");
CurrentImagesFolder.Value = DefaultImageFolder;

UploadPanel.Visible = UploadIsEnabled;

string FileErrorMessage = "";
string ValidationString = ".*(";
//[\.jpg]|[\.jpeg]|[\.jpe]|[\.gif]|[\.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) {

}
} else {

}
}

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 = DateTime.Now.ToString("yyMMddhhmm")+"_"+UploadFileName.Substring(UploadFileName.LastIndexOf("\\")+1);
UploadFileDestination = Request.PhysicalApplicationPath;
UploadFileDestination += CurrentImagesFolder.Value;
UploadFileDestination += "\\";
UploadFile.PostedFile.SaveAs(UploadFileDestination + UploadFileName);
ResultsMessage.Text = UploadSuccessMessage;
DisplayImages(UploadFileName);
Image1.Visible = true;
} catch(Exception ex) {
//ResultsMessage.Text = "Your file could not be uploaded: " + ex.Message;
ResultsMessage.Text = UploadFailureMessage;
}
} else {
ResultsMessage.Text = InvalidFileTypeMessage;
}
} else {
ResultsMessage.Text = NoFileMessage;
}
} else {
ResultsMessage.Text = NoFolderSpecifiedMessage;
}
} else {
ResultsMessage.Text = InvalidFileTypeMessage;

}
}



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 = 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 = Request.PhysicalApplicationPath;
string CurrentFolderPath = AppPath + CurrentImagesFolder.Value;
string[] DirectoriesArray = System.IO.Directory.GetDirectories(CurrentFolderPath,"*");
return DirectoriesArray ;
} catch {
return null;
}
} else {
return null;
}
}

public void DisplayImages(string FileName) {
string filelocation = HttpContext.Current.Request.PhysicalApplicationPath+DefaultImageFolder+"\\"+FileName;
string filevis = HttpContext.Current.Request.ApplicationPath+DefaultImageFolder+"\\"+FileName;
System.Drawing.Image myImage = System.Drawing.Image.FromFile(filelocation);
int Width = myImage.Width;
int Height = myImage.Height;
if(Width > 520) Width=520;
if(Height > 400) Height=400;
myImage.Dispose();
if(System.IO.File.Exists(filelocation))
{
Image1.ImageUrl =Request.ApplicationPath+"/" + DefaultImageFolder.Replace("\\","/")+"/"+ FileName;
Image1.Width = Width; Image1.Height = Height;

Image1.Attributes["ondblclick"]="returnImage('"+ Request.ApplicationPath+"/" + DefaultImageFolder.Replace("\\","/")+"/"+ FileName + "' ,'"+Width+"','"+Height+"');";
}
}
</script>



<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>插入图片</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>
...全文
180 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
luluso 2004-11-24
  • 打赏
  • 举报
回复
看来我可能误解楼主的意思了.sorry
luluso 2004-11-24
  • 打赏
  • 举报
回复
这句.
UploadFileDestination = Request.PhysicalApplicationPath;

修改这里的路径..
xinzhe 2004-11-24
  • 打赏
  • 举报
回复
mark
blureyes2003 2004-10-25
  • 打赏
  • 举报
回复
怎么没有人帮我一下啊。。。急啊。。。!!
spgoal 2004-10-22
  • 打赏
  • 举报
回复
你最好跟踪一下DisplayImages()函数的变量变化情况
blureyes2003 2004-10-22
  • 打赏
  • 举报
回复
这一段吧,,我看是不是虚拟路径出错了啊。。??

public void DisplayImages(string FileName) {
string filelocation = HttpContext.Current.Request.PhysicalApplicationPath+DefaultImageFolder+"\\"+FileName;
string filevis = HttpContext.Current.Request.ApplicationPath+DefaultImageFolder+"\\"+FileName;
System.Drawing.Image myImage = System.Drawing.Image.FromFile(filelocation);
int Width = myImage.Width;
int Height = myImage.Height;
if(Width > 520) Width=520;
if(Height > 400) Height=400;
myImage.Dispose();
if(System.IO.File.Exists(filelocation))
{
Image1.ImageUrl =Request.ApplicationPath+"/" + DefaultImageFolder.Replace("\\","/")+"/"+ FileName;
Image1.Width = Width; Image1.Height = Height;

Image1.Attributes["ondblclick"]="returnImage('"+ Request.ApplicationPath+"/" + DefaultImageFolder.Replace("\\","/")+"/"+ FileName + "' ,'"+Width+"','"+Height+"');";
}
blureyes2003 2004-10-21
  • 打赏
  • 举报
回复
help!!!!!!!!!!!

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧