0

asp.net c# を使用して Web アプリを開発しました。個人の写真をアップロードする必要がある FileUpload コントロールがあります。しかし、ウェブサイトを公開したので、正しく機能していません! ローカル バージョンでは、問題は見られませんでした。私は次のことを試してきました:

  1. web.config で HttpRuntime を確認 => executionTime="60", maxRequestLength="4097151"
  2. ネットで検索しても何も出てこない

これが私のコードです:

fupImage.SaveAs(Server.MapPath(@"\UploadedImages\" + fupImage.FileName));
fupImage.SaveAs(Server.MapPath(@"\UploadedImages\" + fupImage.FileName));

それの何が問題なのですか?

4

1 に答える 1

1

Make sure you have set form enctype="multipart/form-data" and path where you are saving does exist and you have permission. you can check it by debugging..

Here is complete code

<form id="Form1" method="post" action="/home/save" enctype="multipart/form-data">
   <input type="file" name="file" />
    <input type="submit" value="OK" />
</form>

 [HttpPost]
    public ActionResult Save(HttpPostedFileBase file)
    {
        // Verify that the user selected a file
        if (file != null && file.ContentLength > 0) 
        {
            // extract only the fielname
            var fileName = Path.GetFileName(file.FileName);
            // store the file inside ~/App_Data/uploads folder
            var path = Path.Combine(Server.MapPath("~/UploadedImages"), fileName);
            file.SaveAs(path);
        }
        // redirect back to the index action to show the form once again
        return RedirectToAction("Index");        
    }
于 2013-02-24T10:55:46.420 に答える