关于图片上传到服务器上后的路径的问题

hua_nan_she 2010-05-23 12:56:36
在我的本地计算机上用利用回调实现的无刷新图片预览和上传,可以成功,但是发布到服务器上就会出现路径的问题,如果需要粘代码,请给个明示,谢谢个为,帮忙看看
...全文
359 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
hua_nan_she 2010-05-26
  • 打赏
  • 举报
回复
我知道了。就是服务器的问题,不是代码的,呵呵
hua_nan_she 2010-05-24
  • 打赏
  • 举报
回复


<form id="form1" runat="server">
<div>
<div>

<div id="div1"
style ="position :absolute; top: 21px; left: 19px; height: 440px; width: 174px;">
<asp:TextBox ID="txtlike" runat="server" Height="17px" Width="162px"></asp:TextBox>
<asp:Button ID="btnFind"
runat="server" Text="临床表现" Height="18px" Width="166px"
onclick="btnFind_Click" />
<asp:ListBox ID="lbFourDiagnostic" runat="server" Height="407px" Width="165px"
AutoPostBack="True"
onselectedindexchanged="lbFourDiagnostic_SelectedIndexChanged"></asp:ListBox>
</div>
<div id="div2" style ="position:absolute; top: 23px; left: 196px; width: 488px;">
<table style="width: 512px" >
<tr><td class="style1"> 四诊 </td><td>
<asp:Label ID="lbFour" runat="server" Text="">望</asp:Label>
</td></tr>
<tr><td class="style1">诊断类型</td><td>
<asp:TextBox ID="txtType" runat="server" Height="32px" Width="406px"></asp:TextBox></td></tr>
<tr><td class="style1">诊断部位</td><td>
<asp:TextBox ID="txtdiagnoseParts" runat="server" Height="32px" Width="406px"></asp:TextBox></td></tr>
<tr><td>症状</td><td>
<asp:TextBox ID="txtzhengzhuang" runat="server" Height="36px" Width="403px"></asp:TextBox></td></tr>
<tr><td>症候</td><td>
<asp:TextBox ID="txtzhenghou" runat="server" Height="35px" Width="403px"></asp:TextBox></td></tr>

<tr><td class="style1">临床表现</td><td>
<asp:TextBox ID="txtmanifestation" runat="server" Height="72px"
TextMode="MultiLine" Width="405px"></asp:TextBox></td></tr>
<tr><td class="style1">临床意义</td><td>
<asp:TextBox ID="txtsignification" runat="server" Height="78px"
TextMode="MultiLine" Width="403px"></asp:TextBox></td></tr>
<tr><td class="style1">关键字注释</td><td>
<asp:TextBox ID="txtKeywordNote" runat="server" Height="78px"
TextMode="MultiLine" Width="403px"></asp:TextBox></td></tr>

<tr>
<td >图片:</td>
<td>
<asp:FileUpload ID="fpImage" runat="server" Width="303px"
onchange="ShowImage(this)" name="file1" />
</td>
</tr>
<tr>
<td align="center" colspan="2">
<img id="images" alt="" height="100px" width="100px"/>
</td>
</tr>
</table>
<table style="width: 475px"><tr><td>
<asp:LinkButton ID="btnTongyici" PostBackUrl="~/BaseData/TongYiCi.aspx"
runat="server" onclick="btnTongyici_Click">添加同义词</asp:LinkButton>
</td><td>
<asp:Button ID="btnDelete" runat="server" Text="删除" onclick="btnDelete_Click"
style="height: 26px"/></td><td>
<asp:Button ID="btnUpdate" runat="server" Text="修改" onclick="btnUpdate_Click"/></td><td>
<asp:Button ID="btnAdd" runat="server" Text="添加" Height="26px"
onclick="btnAdd_Click" Width="40px"/></td>
</td><td><asp:Button ID="btnImage" runat="server" Text="添加图片"
onclick="btnImage_Click" /></td></tr></table>
</div>
</div>
</div>
</form>
</body>
</html>
<script type="text/javascript">

var newPath = "";
var filePath = "";

function ShowImage(obj) {

filePath = obj.value;

CallServer(obj.value, ' ');
}

//在page_load中的“注册回调脚本”
function ReceiveServerData(rValue) {

newPath = rValue;
//CreateImagetoImg();
//显示图片
document.getElementById("images").src = newPath;
}
</script>





cs中的



protected void Page_Load(object sender, EventArgs e)
{
string sbScript = ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context");

if (!ClientScript.IsClientScriptBlockRegistered("CallServer"))
{
string cbScript = @"function CallServer(arg,context){" + sbScript + "}";

ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServer", cbScript, true);
}
}

#region ICallbackEventHandler 成员

public string GetCallbackResult()
{
try
{

string fileName = System.IO.Path.GetFileName(returnValue);
string imgPath = Server.MapPath("ImageFiles/");
string fullPath = imgPath + fileName;//完整的路径

Stream s = File.OpenRead(returnValue);//读取文件
byte[] buffer = new byte[s.Length];
s.Read(buffer, 0, (int)s.Length);

int len = (int)s.Length;

s.Dispose();
s.Close();


FileStream stream = new FileStream(fullPath, FileMode.Create);
stream.Write(buffer, 0, len);

Bitmap map = new Bitmap(stream);


if (System.IO.Path.GetExtension(returnValue).Equals("gif"))
{
map.Save(stream, ImageFormat.Gif);
}
else if (System.IO.Path.GetExtension(returnValue).Equals("jpg"))
{
map.Save(stream, ImageFormat.Jpeg);
}


map.Dispose();

stream.Dispose();

stream.Close();

return "ImageFiles/" + fileName;
}
catch (Exception e)
{

return null;
}
}

public void RaiseCallbackEvent(string eventArgument)
{
try
{
if (!string.IsNullOrEmpty(eventArgument))
{
string fileName = eventArgument.Substring(eventArgument.LastIndexOf("\\") + 1);//获取文件名称

string geshi = fileName.Substring(fileName.LastIndexOf('.') + 1);//获取文件格式

//执行绘制缩略图
System.Drawing.Image image = MakeThumbnail(eventArgument, "ImageFiles/" + time + fileName, 100, 100);

//image.Save("/ImageFiles/" + time + fileName);
//image.Save(Server.MapPath("ImageFiles/") + time + fileName);
eventArgument = Server.MapPath("ImageFiles/") + time + fileName;
//eventArgument = "ImageFiles/" + time + fileName;

image.Dispose();

returnValue = eventArgument;
}
}
catch (Exception e)
{
;
}
}


/// <summary>
/// 生成缩略图
/// </summary>
/// <param name="sPath">原图片的路径</param>
/// <param name="newSPath">新生成的图片的路径</param>
/// <param name="newWidth">生成缩略图的宽度</param>
/// <param name="newHeight">生成缩略图的高度</param>
/// <returns>缩略图</returns>
public System.Drawing.Image MakeThumbnail(string sPath, string newSpath, int newWidth, int newHeight)
{
try
{
System.Drawing.Image sImage = System.Drawing.Image.FromFile(sPath);

//保存要生成的缩略图的宽度和高度
int nw = newWidth;
int nh = newHeight;

//原始图片的高度和宽度
int sw = sImage.Width;
int sh = sImage.Height;

//如果原始宽度大于缩略图的宽度
if (sw > nw)
{
sw = nw;
}
//如果原始高度大于缩略图的高度
if (sh > sw)
{
sh = sw;
}

sImage = new System.Drawing.Bitmap(sPath);//绘制原路径的图片

System.Drawing.Bitmap sNewImage = new System.Drawing.Bitmap(sImage, sw, sh);//绘制新图片

sNewImage.Save(newSpath);

sImage.Dispose();

sNewImage.Dispose();

return sNewImage;

}
catch (Exception e)
{
return null;
}

}

xlj_2008 2010-05-23
  • 打赏
  • 举报
回复
贴代码看看
hua_nan_she 2010-05-23
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 mngzilin 的回复:]
那你就检查路径,输出路径看看服务器路径的变化再做相应修改
[/Quote]

路径得到了,就是不正确,路径就变成C:\WINDOWS\system32\inetsr
闲游四疯 2010-05-23
  • 打赏
  • 举报
回复
文件夹修改删除操作权限
路径检查
mngzilin 2010-05-23
  • 打赏
  • 举报
回复
那你就检查路径,输出路径看看服务器路径的变化再做相应修改
wuyq11 2010-05-23
  • 打赏
  • 举报
回复
路径操作权限

62,052

社区成员

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

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

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

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