我有一个本地的网站项目,并与数据库连接,服务器中的数据库。我可以添加我在本地工作的照片和国家,但我无法添加我将项目加载到服务器
public void resim_ekle() { if(FileUpload1.HasFile) { 尝试 { string fileExtension = Path.GetExtension(FileUpload1.FileName).ToLower();
string fileName = Guid.NewGuid().ToString(); // şifreli isim
string fileName2 = Guid.NewGuid().ToString();
if (File.Exists(fileName + fileExtension))
fileName = Guid.NewGuid().ToString();
if (File.Exists(fileName2 + fileExtension))
fileName2 = Guid.NewGuid().ToString();
if (FileUpload1.FileContent == null)
return;
if (FileUpload1.FileContent.Length == 0)
return;
System.Drawing.Bitmap originalBMP = new System.Drawing.Bitmap(FileUpload1.FileContent);
int origWidth = 800;
int origHeight = 600;
int origWidth2 = 120;
int origHeight2 = 90;
double sgnRatio = Convert.ToDouble(origWidth) / Convert.ToDouble(origHeight);
double sgnRatio2 = Convert.ToDouble(origWidth2) / Convert.ToDouble(origHeight2);
System.Drawing.Bitmap newBMP = new System.Drawing.Bitmap(originalBMP, origWidth, origHeight);
System.Drawing.Bitmap newBMP2 = new System.Drawing.Bitmap(originalBMP, origWidth2, origHeight2);
System.Drawing.Graphics oGraphics = System.Drawing.Graphics.FromImage(newBMP);
System.Drawing.Graphics oGraphics2 = System.Drawing.Graphics.FromImage(newBMP2);
oGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
oGraphics2.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
oGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low;
oGraphics2.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low;
oGraphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
oGraphics2.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
oGraphics.DrawImage(originalBMP, 0, 0, origWidth, origHeight);
oGraphics2.DrawImage(originalBMP, 0, 0, origWidth2, origHeight2);
newBMP.Save(Server.MapPath("~/resimler/olkeler/" + fileName.ToString() + fileExtension));
newBMP2.Save(Server.MapPath("~/resimler/olkeler/kucuk/" + fileName2.ToString() + fileExtension));
olkeler ulke = new olkeler();
ulke.resim_buyuk = ("~/resimler/olkeler/" + fileName.ToString() + fileExtension).ToString();
ulke.resim_kucuk = ("~/resimler/olkeler/kucuk/" + fileName2.ToString() + fileExtension).ToString();
ulke.olke_adi = txtulke_adi.Text;
vt.insert_ulke(ulke);
label_Uyari.Text = "Resim Başarıyla Yüklendi...";
}
catch { label_Uyari.Text = "Resim Yükleme İşlemi Esnasında Bir Hata Oluştu. Lütfen Tekrar Deneyiniz..."; }
}
else { label_Uyari.Text = "Resim Seçilmemiş..."; }
}
此代码在我的loclhost中运行,但在服务器中不起作用。 FileUpload1
在服务器中没有文件
答案 0 :(得分:1)
我认为你的
是错的newBMP.Save(Server.MapPath("~/resimler/olkeler/" + fileName.ToString() + fileExtension));
我认为你应该放弃〜
我写道:
profilPic.SaveAs(Server.MapPath(@"images/people/") +
profilPic.FileName);
从这里开始:
<asp:FileUpload ID="profilPic" runat="server" />