图片上传在服务器中不起作用。在本地主机上工作正常
Image Upload doesn't work in Server. Works fine in localhost
所以,这段代码在本地主机上工作得很好。它删除以前的图像并上传新图像。但是它在服务器上什么也不做。有什么线索吗?
我已经使用 AJAX 进行异步调用顺便说一下,如果这有什么不同的话。
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。
所以,这段代码在本地主机上工作得很好。它删除以前的图像并上传新图像。但是它在服务器上什么也不做。有什么线索吗?
我已经使用 AJAX 进行异步调用顺便说一下,如果这有什么不同的话。
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。