图像上传在服务器中不起作用.在本地主机上工作正常 [英] Image Upload doesn't work in Server. Works fine in localhost
本文介绍了图像上传在服务器中不起作用.在本地主机上工作正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以,这段代码在本地主机上运行得很好.它会删除上一张图片并上传新图片.但是它在服务器上什么都不做.有什么线索吗?
So, this code works just fine in localhost. It deletes the previous image and uploads the new one. It does nothing on server however. Any clue?
顺便说一下,我已经使用 AJAX 进行异步调用了.
I have used AJAX for asynchorous call By the way if that makes a difference.
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.
Try changing the permission of the folder to 777.
这篇关于图像上传在服务器中不起作用.在本地主机上工作正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文