麻烦保存在PHP中图片上传 [英] trouble save the image upload in php

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

问题描述

我有这个母版页和母版页我的问题是,code不会运行或保存到我想要的文件夹,一个Web表单,让我怎么改变code在VB的?
 基本上我有有一个输入,让我上载文件或图像一个javascript,但问题,它似乎总喜欢里面跳过

的code

 <脚本类型=文/ JavaScript的>
            变种计数器= 0;            功能AddFileUpload(){
                VAR的div = document.createElement方法('DIV');
                div.innerHTML ='<输入ID =文件'+专柜+'NAME =文件'+专柜+'类型=文件/><输入ID =按钮+专柜+'型=按钮值=删除的onclick =RemoveFileUpload(本)/>';
                的document.getElementById(FileUploadContainer)的appendChild(DIV)。
                反++;
            }
            功能RemoveFileUpload(DIV){
                的document.getElementById(FileUploadContainer)removeChild之(div.parentNode)。
            }
            $(文件)。就绪(函数(){
                AddFileUpload();
            });        < / SCRIPT>
<跨度风格=FONT-FAMILY:宋体>点击添加文件< / SPAN>&安培; NBSP;&安培; NBSP;        < BR />< BR />
        < D​​IV ID =FileUploadContainer>
            <! - 的FileUpload控件将在这里添加 - >
        < / DIV>
        < BR />
        <输入ID =ButtonAdd类型=按钮值=增加的onclick =AddFileUpload()/>
        < ASP:按钮的ID =btnUpload=服务器文本=上传/>
    < ASP:标签ID =LBL2=服务器前景色=红>< / ASP:标签>
        < BR />     保护小组btnUpload_Click(BYVAL发件人为对象,BYVAL E上System.EventArgs)把手btnUpload.C​​lick
            对于我作为整数= 0〜Request.Files.Count - 1
                昏暗PostedFile作为HttpPostedFile = Request.Files(I)
                如果PostedFile.ContentLength> 0,则
                    昏暗的文件名作为字符串= System.IO.Path.GetFileName(PostedFile.FileName)
                    PostedFile.SaveAs(使用Server.Mappath(文件\\ IMG \\)+文件名)                其他
                    lbl2.Text =没有图像已选择要上传
                万一
            下一个
        结束小组


解决方案

你的问题是有点混乱。但通过我从你的问题理解的事情。如果u有形式加入到您的内容形式U可以从母版页删除表格,然后我只好表单添加到您将添加每个内容形式的问题,我会说。

卜如果你想在你的页面多种形式U可以通过只有一种形式一次看到这样做的。

但看到它的形式是从其中一个已在它有另一种形式的占位符。
问题是有点混乱,但希望我能够给ü解决方案...

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

    <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>  


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

        <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

解决方案

Your question is a bit confusing.. But by the things that i have understood from your question. i would say if u have problem of adding forms into your content form u can remove form from the master page and then u have to add forms to each content form you will add.

Bu if you want multiple forms in your page u can do so by making only one form visible at a time.

But see to it that the form is in another placeholder from the one which already had form in it. Question is a bit confusing but hope i was able to give u solution ...

这篇关于麻烦保存在PHP中图片上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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