最近在研究图片上传并且保存到数据库中(access数据库)然后再上传中遇到问题了
stringpath=FileUpload1.PostedFile.FileName.ToString();
stringsPath=Server.MapPath(\"../upload/\"path);这句代码是不是意味着在挑选图片上传的时候要挑选upload文件夹下的图片?我试了一下上传在F:\\网络相册\\upload\\13-05-11_10.26[01].jpg的这张图,但是运行到这句代码的时候他说:“不是有效的虚拟路径”
那请问问题出在哪里了?
我的上传按钮的事件代码如下:
protectedvoidbtnadd_Click(objectsender,EventArgse)
{
//stringid=newRandom().Next(1,1000).ToString();
//将附件传送到服务器上
stringpath=FileUpload1.PostedFile.FileName.ToString();//获取上传图片路径
stringext=path.Substring(path.LastIndexOf(\".\")1);//获取图片扩展名
if(ext.ToLower()==\"jpg\"||ext.ToLower()==\"bmp\"||ext.ToLower()==\"gif\"||ext.ToLower()==\"png\"||ext.ToLower()==\"tif\"||ext.ToLower()==\"jpeg\")
{
stringphototitle=this.txttitle.Text.ToString();
stringphotocontent=this.txtcontent.Text.ToString();
stringwPath=\"../upload/\"path;
stringsPath=Server.MapPath(\"../upload/\"path);//设置图片保存到服务器上路径
stringsuoPath=Server.MapPath(\"../suo/\")path;
//path=\"..\\\\Photo\\\\\"PhotoID\".\"ext;//保存到数据库中路径
FileUpload1.PostedFile.SaveAs(sPath);//保存到服务器
stringurlPath=wPath;
stringphotoUser=\"admin\";
inttype=Convert.ToInt32(this.dropdownlists.SelectedValue.ToString());
intcount=newphoto().addpic(phototitle,type,path,photocontent,photoUser);
if(count0)
{
PictureSlightly.MakeImage(sPath,suoPath,100,100,\"hw\");
this.Page.ClientScript.RegisterStartupScript(this.GetType(),null,\"scriptalert(\'添加成功!\');/script\");
}
else
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(),null,\"scriptalert(\'添加失败!\');/script\");
}
}
else
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(),null,\"scriptalert(\'只能上传图片!\');/script\");
}
}
最好能将每句代码的意思都说一下哈,谢谢啦~
|