Ajax 图像上传不';我不能在服务器上工作。在localhost中运行良好
因此,这段代码在localhost中运行良好。它删除以前的图像并上载新图像。然而,它在服务器上什么也不做。有线索吗 顺便说一句,我已经使用AJAX进行了异步调用,如果这有什么不同的话Ajax 图像上传不';我不能在服务器上工作。在localhost中运行良好,ajax,razor,webmatrix,Ajax,Razor,Webmatrix,因此,这段代码在localhost中运行良好。它删除以前的图像并上载新图像。然而,它在服务器上什么也不做。有线索吗 顺便说一句,我已经使用AJAX进行了异步调用,如果这有什么不同的话 var db=Database.Open("StarterSite"); var contentQuery="Select * from Contents where id =@0"; var content=db.QuerySingle(contentQuery,"1"); var message
var db=Database.Open("StarterSite");
var contentQuery="Select * from Contents where id =@0";
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 +"=@0";
db.Execute(updateQuery, fileName);
//Response.Redirect("editMode.cshtml");
}
}
}
catch(HttpException ex){
message="Image size you selected was too large. Please select a different Image.";
}
尝试将文件夹的权限更改为777。
var fullPath=Server.MapPath(“~/img/”+toDelete)代码>尝试使用相对路径。你能告诉我更多吗?转到你的服务器,进入img
目录,点击那里的pwd
,用新值替换你代码中的~/img
。你能告诉我怎么做吗?在你的filezilla中,访问服务器,右键单击文件夹并更改权限。试试755或777。但我没有使用filezilla。我正在webmatrix中使用web部署。我明白了。你是如何在你的服务器上上传文件的?你在哪里可以从服务器上查看你的文件夹?我对这个很陌生。我不知道如何从服务器访问文件。我只知道如何上传。可能是我的主人,因为我只付5块钱,所以没有这项服务?