图片上传,如何实现保存相对路径?
代码如下 :
.aspx
<input id="uploadFile" type="file" name="uploadFile" runat="server">
.cs
if(!(uploadFile.PostedFile.ContentLength>0))
{
lblErrInfo.Text="没有选择文件";
}
else
{
string path1 = uploadFile.PostedFile.FileName; //path1中保存的是 绝对路径 我现在想变成虚拟路径 如何实现。谢谢!
string path = Server.MapPath("./Uploads/"+uploadFile.PostedFile.FileName.Substring(uploadFile.PostedFile.FileName.LastIndexOf('\\')+1));
if(File.Exists(path))
{
lblErrInfo.Text="已经有同名文件";
}
else
{
uploadFile.PostedFile.SaveAs(path);
ImgPreview.Visible = true;
ImgPreview.ImageUrl = path;
}
}