它不断将图像保存到本地目录或根本不保存。它没有给我任何错误。据我所知,我的本地驱动器和主机之间没有关系。我所有的页面都在主机上,它们工作正常。但在创建此页面之前,我将 bin 目录文件(AjaxControlToolkit.dll、Site.dll、site.pdb)从本地主机导入到 Web 服务器。
源文件:
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolderIcerik" runat="server">
<asp:ToolkitScriptManager runat="server"></asp:ToolkitScriptManager>
<asp:AjaxFileUpload ID="AjaxFileUploadResimEkle" runat="server"
AllowedFileTypes="jpg,jpeg"
onuploadcomplete="AjaxFileUploadResimEkle_UploadComplete" />
</asp:Content
>
代码隐藏:
protected void AjaxFileUploadResimEkle_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
int PostID = Convert.ToInt32(Request.QueryString["PostID"]);
var makale = (from p in db.Posts
where p.PostID == PostID
select new { p.PostID, p.Title }).Single();
string uzanti = Path.GetExtension(e.FileName);
if (e.ContentType.Contains("image"))
{
if (e.FileSize <41943040)
{
Guid benzersiz = Guid.NewGuid();
string filePath =string.Format("~/images/blog/large_image/{0}_{1}{2}", makale.Title, benzersiz,uzanti);
AjaxFileUploadResimEkle.SaveAs(Server.MapPath(filePath));
System.Drawing.Image degisecekResim = System.Drawing.Image.FromFile(filePath));
Bitmap kucukResim = ResimKucult(degisecekResim);
string kucukResimYolu = string.Format("~/images/blog/medium_image/{0}_{1}{2}", makale.Title, benzersiz,uzanti);
kucukResim.Save(Server.MapPath(kucukResimYolu));
Resimler resim = new Resimler();
resim.PostID = PostID;
resim.FileName = filePath;
resim.SmallFileName = kucukResimYolu;
resim.IsActive = true;
db.Resimlers.AddObject(resim);
db.SaveChanges();
}
}
}
Bitmap ResimKucult(System.Drawing.Image resim)
{
int x = 225;
int y = 165;
Bitmap bmpOrji = new Bitmap(resim);
if (bmpOrji.Width > bmpOrji.Height)
{
y = bmpOrji.Height * x / bmpOrji.Width;
}
else if (bmpOrji.Height > bmpOrji.Width)
{
x = bmpOrji.Width * y / bmpOrji.Height;
}
Bitmap yeniBmp = new Bitmap(bmpOrji, x, y);
return yeniBmp;
}
}