图像上传在服务器中不起作用。在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."; 
    } 
+0

'变种FULLPATH =使用Server.Mappath( “〜/ IMG /” + toDelete);'尝试使用相对路径来代替。 – TheChetan

+0

你能告诉我多一点吗? – Npandit

+0

转到您的服务器并进入'img'目录,点击'pwd'并用新值替换代码中的〜/ img'。 – TheChetan

尝试改变该文件夹的权限777

+0

你能告诉我该怎么做吗? – Npandit

+0

在您的filezilla中,访问您的服务器并右键单击该文件夹并更改权限。尝试755或777. http://www.dummies.com/web-design-development/wordpress/navigation-customization/how-to-change-file-permissions-using-filezilla-on-your-ftp-site/ –

+0

但我没有使用filezilla。我正在webmatrix中使用web部署。 – Npandit