!!!!迫切需要有关图片上传的帮助,无法保存 [英] !!!!need urgently help on image upload not able to save

查看:72
本文介绍了!!!!迫切需要有关图片上传的帮助,无法保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此母版页和具有母版页的Web表单,我遇到的问题是代码无法运行或保存到我想要的文件夹中,那么如何更改vb中的代码?
基本上我有一个javascript,它的输入可以让我上传文件或图像,但是问题是,好像总跳过了里面的代码

i have this master page and a web form with the master page the problem i have is that the code wont run or save into the folder i want it to, so how do i change the code in the vb?
basically i have a javascript which have a input that allow me to upload a file or image, but the problem, it seem like total skip the code inside

<span style ="font-family:Arial">Click to add files</span>&nbsp;&nbsp;
<pre lang="HTML"><span style ="font-family:Arial">Click to add files</span>  

    <br /><br />
    <div id = "FileUploadContainer">
        <!--FileUpload Controls will be added here -->
    </div>
    <br />
    <input id="ButtonAdd" type="button" value="add" onclick = "AddFileUpload()" />
    <asp:Button ID="btnUpload" runat="server" Text="Upload"  />
<asp:Label ID="lbl2" runat="server" ForeColor="Red"></asp:Label>
    <br />


Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
        For i As Integer = 0 To Request.Files.Count - 1
            Dim PostedFile As HttpPostedFile = Request.Files(i)
            If PostedFile.ContentLength > 0 Then
                Dim FileName As String = System.IO.Path.GetFileName(PostedFile.FileName)
                PostedFile.SaveAs(Server.MapPath("Files\img\") + FileName)

            Else
                lbl2.Text = "No images have been selected to upload "
            End If
        Next
    End Sub


<script type = "text/javascript">
       var counter = 0;

       function AddFileUpload() {
           var div = document.createElement('DIV');
           div.innerHTML = '<input id="file' + counter + '" name = "file' + counter + '" type="file" /><input id="Button' + counter + '" type="button" value="Remove" onclick = "RemoveFileUpload(this)" />';
           document.getElementById("FileUploadContainer").appendChild(div);
           counter++;
       }
       function RemoveFileUpload(div) {
           document.getElementById("FileUploadContainer").removeChild(div.parentNode);
       }
       $(document).ready(function () {
           AddFileUpload();
       });

   </script>

推荐答案

(文档).ready(功能(){ AddFileUpload(); }); </script>
(document).ready(function () { AddFileUpload(); }); </script>


我认为您的"mappath"需要以/开头以映射到应用程序根目录.除此之外,根据您模糊的描述,我不确定出什么问题或可能出什么问题.
I think your ''mappath'' needs to start with a / to map to the application root. Beyond that, based on your vague description, I''m not sure what''s going wrong or what the problem could be.


这篇关于!!!!迫切需要有关图片上传的帮助,无法保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆