0

我有下面的代码。这是一种允许用户上传文件的表单。如果他们上传的文件与列出的文件相对应,我已经包含了用户应该勾选的复选框。然后我想检查正在上传的文件是否具有与从列表中选择的复选框相对应的文件名:

<!--SCRIPT 2 ensures that text fields are not left blank on Project form-->
    <!--SCRIPT 2 START-->
    <script type="text/javascript">
        function validateproject()
        {
            valid = true;
            if (document.input.bhu_no.value == "")
                {
                alert ("Please enter a BHU #")
                valid = false;
                }
            else if (document.input.projectname.value == "")
                {
                alert ("Please enter a Project Name")
                valid = false;
                }       
            else if (document.input.projectlead.value == "")
                {
                alert ("Please enter a the Project Lead Name")
                valid = false;
                }   
            else if (document.input.projectgoal.value == "")
                {
                alert ("Please enter a Project Goal Description")
                valid = false;
                }   
            else if (document.input.projectstartdate.value == "")
                {
                alert ("Please enter a Project Start Date")
                valid = false;
                }   
            else if (document.input.projectenddate.value == "")
                {
                alert ("Please enter a Project End Date")
                valid = false;
                }
            /*else if (document.input.brd.value == "BRD")
                {
                alert ("Please upload a BRD with BRD in the title")
                valid = false;
                }   */
            else if(document.getElementById("uploaded").value == "")
                {
                alert ("Please attach a file to be uploaded")
                valid = false;
                }                       
            return valid;
        }   
    </script>
    <!--SCRIPT 2 END-->
    <head>
<body id="wrapper">
    <script type='text/JavaScript' src='calendarwidget.js'></script>
<!--////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                    PROJECT FORM START
    \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
-->         
            <center><a href="#" class="show_hide"><input style="font-size:16px;" type="button" value="Rules for Uploading Files" /></a></center>
            <div class="slidingDiv">
                <ul>
                    <li type="1">
                        Creation of folders manually without filling out upload forms should not be done
                    </li>
                    <br />
                    <li type="1">
                        File names should be descriptive and give information about what is contained within the file
                    </li>
                    <br />
                    <li type="1">
                        Files uploaded must be in either Read or Read/Write property otherwise others will not be able to view the files
                    </li>
                    <br />
                    <li type="1">
                        Fill out text fields on upload forms fully and to the best of your knowledge
                    </li>
                    <br />
                    <li type="1">
                        Try and have the most recent document on the server at all times. If you want to keep many versions of a document on the server the 
                        file name must end with underscore ‘_’ , capital ‘V’ and the version number (e.g. ‘KB How-to_V4.key’).
                    </li>
                    <br />
                    <li type="1">
                        At the end of a project upload all files related to the project onto the Knowledge Base
                    </li>
                    <br />
                    <li type="1">
                        Documents uploaded to the server can not be edited, if you wish to edit a document contact the uploader of the document
                    </li>
                    <br />
                    <li type="1">
                        When you have completed mass uploading files to the server ensure you ‘Eject’ the server
                    </li> 
                </ul>
            </div>




            <div id="selectproject">    
            <br />
            <br />      
                <form name="input" action="uploadproject.php" enctype="multipart/form-data" method="post" onsubmit="return validateproject();">
                    <table class="bordered">
                        <tr>
                            <th>
                                BHU #
                            </th>
                            <td>
                                <input class="uploadform" type="text" name="bhu_no" maxlength="4" size="4"/>
                                <a style='font-size:12px;' href="https://biweb3.corp.apple.com/compliance/index.php/concept/search" target="_blank"><i>Search for BHU #</i></a>
                            </td>
                        </tr>
                        <tr>    
                            <th>
                                Project Name
                            </th>
                            <td>
                                <input class="uploadform" size="50" type="text" name="projectname" onkeyup="valid(this)" onblur="valid(this)" />
                            </td>
                        </tr>
                        <tr>    
                            <th>
                                Project Lead
                            </th>
                            <td>
                                <input class="uploadform" size="18" type="text" name="projectlead"/>
                            </td>
                        </tr>
                            <tr>    
                            <th>
                                Project Wiki
                            </th>
                            <td>
                                <input class="uploadform" size="50" type="text" name="projectwiki"/>
                            </td>
                        </tr>
                        <tr>
                            <th>
                                BPR Track
                            </th>
                            <td>
                                <select name="bprtrack">
                                    <option value="">
                                        --BLANK--
                                    </option>   
                                    <option value="Manufacturing">
                                        Manufacturing
                                    </option>
                                    <option value="Logistics">
                                        Logistics
                                    </option>
                                    <option value="Supply Chain">
                                        Supply Chain
                                    </option>
                                    <option value="AOS">
                                        AOS                                     
                                    </option>
                                    <option value="Supply/Demand Management">
                                        Supply/Demand Management                                        
                                    </option>
                                    <option value="Procurement">
                                        Procurement                                     
                                    </option>
                                    <option value="BI">
                                        BI                                      
                                    </option>
                                    <option value="Emerging Markets">
                                        Emerging Markets
                                    </option>                                   
                                </select>
                            </td>   
                        </tr>
                        <tr>    
                            <th>
                                Project Goal
                            </th>
                            <td>
                                <textarea class="uploadform" rows="7" cols="50" name="projectgoal"></textarea>
                            </td>
                        </tr>   
                        <tr>    
                            <th>
                                Date Start
                            </th>
                            <td>
                                <INPUT TYPE='text' class="uploadform" id="projectstartdate" name="projectstartdate" SIZE='12' maxlength="10" />
                                <img src='Images/scw.gif' title='Click Here' alt='Click Here' onclick="scwShow(scwID('projectstartdate'),event);" />
                            </td>
                        </tr>
                        <tr>    
                            <th>
                                Date End
                            </th>
                            <td>
                                <input type="text" class="uploadform" id="projectenddate" name="projectenddate" SIZE='12' maxlength="10" />
                                <img src='Images/scw.gif' title='Click Here' alt='Click Here' onclick="scwShow(scwID('projectenddate'),event);" />
                            </td>
                        </tr>
                        <tr>    
                            <th>
                                Process(es) Effected<br />
                                <i style='font-size:12px;'>(User Inputted, not required)</i>
                            </th>
                            <td>
                            <div class='container'>
                                <?php

                                    $Results = mysql_query("SELECT processname FROM Knowledge.Process");

                                    while($Loadingrow = mysql_fetch_array($Results)) 
                                    {               
                                    echo "<input type='checkbox' value='$Loadingrow[processname]*' name='processname[]'>";
                                    echo $Loadingrow['processname'];
                                    echo "<br />";
                                    };
                                ?>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <th>Files Uploaded</th>
                            <td>
                                <input class="uploadform" type="checkbox" name="brd" value="BRD"/>BRD<br />
                                <input class="uploadform" type="checkbox" name="playback" value="playback"/>Playback Doc.<br />
                                <input class="uploadform" type="checkbox" name="function" value="function"/>Functional Spec.<br />
                                <input class="uploadform" type="checkbox" name="work" value="work"/>Work Instruction<br />
                                <input class="uploadform" type="checkbox" name="processf" value="processf"/>Process Flow<br />
                            </td>
                            </tr>                           
                            <tr>    
                            <th>
                                Upload File
                            </th>
                            <td>
                                <input type="file" name="uploaded" />
                            </td>
                        </tr>
                </table>
                <br />  
                <input style='font-size:2em;' type="submit" value="Upload All" name="upload"/>
        </form>
        </div>
</body>

我想知道如何检查是否选中了“brd”复选框以及正在上传的文件是否具有特定名称。如果文件名正确,则应完成上传,否则应抛出错误消息。我不知道如何在页面发布之前检查复选框,我也不知道如何检查正在上传的文件的文件名......有人可以指导我正确的方向吗?

谢谢!

4

2 回答 2

0

要检查一个复选框是否在 Javascript 中被选中,你需要这样做。

if(document.input.projectstatus.checked == true) {

    // CODE GOES HERE

}

假设projectstatus是一个复选框名称。

然后检查上传的文件是否有特定的名称,试试这个。

<?php

   if($_FILES["file"]["name"] == "specificname") {

            // CODE GOES HERE

   }

?>

假设file是表单中的字段名称。

于 2013-02-05T11:09:45.340 回答
0

在您的 JS 中,您已编写

document.getElementById("uploaded")

而在您的 HTML 中,您有

<input type="file" name="uploaded" /> 

请添加ID="已上传"

于 2013-02-05T12:11:46.887 回答