各位大侠:例如小弟想将图片11.jpg上传到服务器。在将图片上传到服务器一个文件夹WorkAnnex内的同时将图片缩略到一定大小并加上水印,经过缩略和水印文字处理的图片命名为11.jpgnew.jpg,同样存放到WorkAnnex文件夹内。同时将11.jpgnew.jpg作为路径存放到数据库表中。 在本地机上没有发现任何问题。但是将网站挂到服务器上之后,作为用户登录后进行上传发现图片控件出现红色的叉号,登录服务器发现数据库内保存的确实是11.jpgnew.jpg,但是WorkAnnex文件夹内只有原来上传的11.jpg图片,没有处理后的11.jpgnew.jpg图片。还请各位大哥赐教。分数不多,略表心意。
为什么在本地机上测试就可以,而在服务器上就不可以呢??
现将代码贴出,还请高手指点。
try
{
if (FileUpload1.HasFile)
{
HttpFileCollection MyFiles = Request.Files; for (int i = 0; i < MyFiles.Count; i++)
{
HttpPostedFile MyPost = MyFiles[i]; try
{
string filepath = MyPost.FileName;
string filename = filepath.Substring(filepath.LastIndexOf("\\") + 1);
string serverpath = Server.MapPath("../WorkAnnex/") + filename
MyPost.SaveAs(serverpath); ImageThumbnail img = new ImageThumbnail(filepath);
img.ReducedImage(480, 360, serverpath);
DrawImg dmg = new DrawImg();
dmg.PublicWorkingDirectory = Server.MapPath("../WorkAnnex/");
dmg.PublicImageName = filename;
dmg.PublicFontString = "ssss";
dmg.DealImage(); }
catch (Exception msgbox)
{
} } } string NewName = ""; if (FileUpload1.FileName == "")
{
NewName = FileUpload1.FileName;
}
else
{
NewName= FileUpload1.FileName + "new.jpg";
}bool result = MyWork.AddWork(TextBox1.Text,TransStringTool.TransString (TextBox2.Text),MyWork.CutString(TextBox1.Text,15),NewName);
}缩略图代码:
public class ImageThumbnail
{
public Image ResourceImage;//需要缩放的图像源文件
private int ImageWidth;//缩放后图像的宽度
private int ImageHeight;//缩放后图像的高度
public string ErrorMessage;//出错信息 public ImageThumbnail(string ImageFileName)
{
ResourceImage = Image.FromFile(ImageFileName);
ErrorMessage = "";
return ;
}
public bool ThumbnailCallback()
{
return false;
} // 方法1,按大小
public bool ReducedImage(int Width, int Height, string targetFilePath)
{
try
{
Image ReducedImage;
Image.GetThumbnailImageAbort callb = new Image.GetThumbnailImageAbort(ThumbnailCallback);
ReducedImage = ResourceImage.GetThumbnailImage(Width, Height, callb, IntPtr.Zero);
ReducedImage.Save(@targetFilePath, ImageFormat.Jpeg);
ReducedImage.Dispose();
return true;
}
} }
现在主要问题集中在为什么在本地机上就没有任何问题,而把它挂到服务器上就不行呢?
为什么在本地机上测试就可以,而在服务器上就不可以呢??
现将代码贴出,还请高手指点。
try
{
if (FileUpload1.HasFile)
{
HttpFileCollection MyFiles = Request.Files; for (int i = 0; i < MyFiles.Count; i++)
{
HttpPostedFile MyPost = MyFiles[i]; try
{
string filepath = MyPost.FileName;
string filename = filepath.Substring(filepath.LastIndexOf("\\") + 1);
string serverpath = Server.MapPath("../WorkAnnex/") + filename
MyPost.SaveAs(serverpath); ImageThumbnail img = new ImageThumbnail(filepath);
img.ReducedImage(480, 360, serverpath);
DrawImg dmg = new DrawImg();
dmg.PublicWorkingDirectory = Server.MapPath("../WorkAnnex/");
dmg.PublicImageName = filename;
dmg.PublicFontString = "ssss";
dmg.DealImage(); }
catch (Exception msgbox)
{
} } } string NewName = ""; if (FileUpload1.FileName == "")
{
NewName = FileUpload1.FileName;
}
else
{
NewName= FileUpload1.FileName + "new.jpg";
}bool result = MyWork.AddWork(TextBox1.Text,TransStringTool.TransString (TextBox2.Text),MyWork.CutString(TextBox1.Text,15),NewName);
}缩略图代码:
public class ImageThumbnail
{
public Image ResourceImage;//需要缩放的图像源文件
private int ImageWidth;//缩放后图像的宽度
private int ImageHeight;//缩放后图像的高度
public string ErrorMessage;//出错信息 public ImageThumbnail(string ImageFileName)
{
ResourceImage = Image.FromFile(ImageFileName);
ErrorMessage = "";
return ;
}
public bool ThumbnailCallback()
{
return false;
} // 方法1,按大小
public bool ReducedImage(int Width, int Height, string targetFilePath)
{
try
{
Image ReducedImage;
Image.GetThumbnailImageAbort callb = new Image.GetThumbnailImageAbort(ThumbnailCallback);
ReducedImage = ResourceImage.GetThumbnailImage(Width, Height, callb, IntPtr.Zero);
ReducedImage.Save(@targetFilePath, ImageFormat.Jpeg);
ReducedImage.Dispose();
return true;
}
} }
现在主要问题集中在为什么在本地机上就没有任何问题,而把它挂到服务器上就不行呢?
//真實物理路徑 string str_ipath = Server.MapPath("b2b_Excel") + "\\" + str_name;
//虛擬路徑 string str_fpath = "b2b_Excel" + "\\" + str_name;
File_Upload.SaveAs(str_ipath);
路徑保存才行。。
你加上File_Upload.SaveAs(str_ipath);
這個就沒問題,我試過了。。
string serverpath = Server.MapPath("../WorkAnnex/") + filename
MyPost.SaveAs(serverpath); ImageThumbnail img = new ImageThumbnail(filepath); //--> serverpath ?
应该就没得问题~