【问题标题】:save the file from the html file upload in asp.net using jquery使用 jquery 保存从 html 文件上传到 asp.net 中的文件
【发布时间】:2011-11-03 07:59:28
【问题描述】:

我有一个 html 上传 <input type="file" id="myfile"/>。当我单击它时,它正在加载文件,但无法在 firefox3 中获取像 c:documents/images... 等这样的完整路径。

我还有一个 html 按钮单击我必须在保存图像时使用 json 将文件保存到我的应用程序的根文件夹中,然后应该打开一个带有浏览图像的弹出窗口,允许用户使用裁剪图像作物。当用户完成裁剪后,应使用 jquery 和 json 并仅使用 html 控件将图像保存回我的根文件夹(服务器端)。

一切都应该使用 jquery 和 json 以及在后面的代码中使用 webmethods 来处理。

这是我的代码:

<input type="file" class="select-file" id="file_attach"  />

    enter code here

$('#btnNextPhoto').click(function () {
                //Cancel the link behavior


                filename = $('#file_attach').val();


                //e.preventDefault();
                if (filename != "") {
                    alert("i am svaing");
                    SaveUncroppedImage();

                }

}

function SubmitUncroppedImage(image) {
    var ticket = getCookieFromPage();
    var DTO = JSON.stringify({ image: image, encryptedTicket: ticket });
    $.ajax({
        type: "POST",
        url: "../Members/EditProfile.aspx/SaveUncroppedImage",
        data: DTO,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            alert(msg.d);
            $("#cropbox").attr('src', msg.d).show();
            $('#container').hide();
        },
        error: function (msg) {
            alert(msg.d);
        }
    });
}


[System.Web.Services.WebMethod]
        public static string SaveUncroppedImage(string image, string encryptedTicket)
        {
            ImageFunctions img = new ImageFunctions();
            string guid = Guid.NewGuid().ToString();
            string fileName = guid + ".jpg";
            //string rPath = "/images/flower.jpg";
            string root = "C:\\Sites\\images\\videothumbs";


            file_attach.SaveAs(root + image);"

【问题讨论】:

  • 今后请提高提问的质量。
  • 请立即检查我的代码
  • 我已尝试(尽我所能)对您的问题进行额外修改。您能否检查它们的正确性,进行任何更改并告诉我?请注意,我的大部分编辑只是在您的问题中添加段落(这是一堵坚固的文字墙)、适当的大写和一些标点符号。如果这充分描述了您的问题,请告诉我,我会重新打开它。

标签: jquery asp.net html json file-upload


【解决方案1】:

您不能使用这样的文件上传控件。 Web 浏览器会阻止您查看本地文件路径。而且我无法判断您是否正在尝试写入客户端的计算机,但您绝对不能这样做,因为这是一个巨大的安全风险。

【讨论】:

  • 我不想写信给客户端机器我只是希望用户上传照片 n 裁剪并将其保存为他的个人资料图片
  • 好的,你的问题到底是什么? “我描述的所有内容的代码是什么?”如果这就是你要找的东西,那么这里的任何人都不会为你写它。你必须展示你已经尝试过的东西。
  • 在 mozila 中,当我点击 browe 时,我可以获得 myimage.jpeg 而不是完整的位置,如 c:.....myimage.jpeg 让我添加我的代码
  • 对,正如我上面解释的,文件上传不会给你那种客户端信息。我知道您并没有尝试写入客户端计算机,但即使该路径也受到 Web 浏览器的保护。没有办法得到它。
  • 那么我们如何保存文件...!我现在很担心。我正在尝试 9 小时,你可以给我一些建议吗
猜你喜欢
  • 2023-04-11
  • 2016-07-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-24
  • 1970-01-01
  • 2012-03-09
  • 2011-08-16
相关资源
最近更新 更多