图像上传在服务器中不起作用。在localhost工作正常
问题描述:
所以,这段代码在localhost中工作得很好。它删除以前的图像并上传新的图像。但是,它在服务器上不做任何事任何线索?图像上传在服务器中不起作用。在localhost工作正常
我已经使用AJAX进行asynchorous调用顺便说一下,如果这有所作为。
var db=Database.Open("StarterSite");
var contentQuery="Select * from Contents where id [email protected]";
var content=db.QuerySingle(contentQuery,"1");
var message="";
var imgCount=0;
var alreadyExist=false;
try{
if (IsPost && Request.Files.Count > 0) {
bool deleteSuccess = false;
var fileName = "";
var photoName = "";
var fileSavePath = "";
var uploadedFile = Request.Files[0];
var toDelete=Request["toDelete"];
var toUpload=Request["toUpload"];
if(uploadedFile.ContentLength>0){
@******************DELETE***************@
var fullPath = Server.MapPath("~/img/" + toDelete);
if (File.Exists(fullPath))
{
File.Delete(fullPath);
deleteSuccess = true;
}
@****************UPLOAD*******************@
fileName = Path.GetFileName(uploadedFile.FileName);
fileSavePath = Server.MapPath("~/img/" +
fileName);
uploadedFile.SaveAs(fileSavePath);
var updateQuery="Update Contents Set "+toUpload +"[email protected]";
db.Execute(updateQuery, fileName);
//Response.Redirect("editMode.cshtml");
}
}
}
catch(HttpException ex){
message="Image size you selected was too large. Please select a different Image.";
}
'变种FULLPATH =使用Server.Mappath( “〜/ IMG /” + toDelete);'尝试使用相对路径来代替。 – TheChetan
你能告诉我多一点吗? – Npandit
转到您的服务器并进入'img'目录,点击'pwd'并用新值替换代码中的〜/ img'。 – TheChetan