0

我正在尝试创建一个表单,用户可以在其中选择一个位置,然后使用CFFILE ACTION ="UPLOAD". 我对此并不擅长,因此您可以提供的任何帮助将不胜感激。

下面是我的代码。本质上,有一个文件夹位置的下拉列表。用户首先选择其中一个位置。然后单击“浏览”以选择一个文件。最后他们点击提交并上传文件。

代码#dir#是链接到每个位置名称的文件夹位置。目前发生的情况是文档已成功上传......但它正在上传到所有文件夹位置,而不是从下拉列表中选择的位置。这是我的代码:

文档上传.cfm

<cfquery name="getLocation">
    SELECT *
    FROM Locations
    ORDER BY FolderName
</cfquery>

<form action="docuploads.cfm" method="POST" enctype="multipart/form-data" name="upload_form" id="upload_form"> 
    <select name="folderID">
        <option value="">--- Select Folder ---</option>
        <cfoutput query="getLocation">
            <option value="#FolderName#"">#FolderName#</option>
        </cfoutput>
    </select>

    <cfoutput query="getLocation">
       <CFIF IsDefined("form.upload_now")>
          <CFIF structKeyExists(form, "ul_path") and len(form["ul_path"])>
             <CFFILE ACTION="UPLOAD" FILEFIELD="ul_path" 
                    DESTINATION="C:\Documents\#dir#\"         
                    NAMECONFLICT="OverWrite">
              <CFSET ClientFilePath = "#clientDirectory#\#clientFile#">
          </CFIF>
      </CFIF>
     </CFOUTPUT>

     <br /><br />
     Click on the Browse button to select the file to Upload:<br>
     <input type="file" name="ul_path" id="ul_path" style="height: 22px;width: 350px;" value=""><br><br>
     <input type="submit" name="upload_now" id="upload_now" value="Submit" style="height: 22px;">
     <input type="button" name="clear" value="Clear" style="height: 22px;">
     <br /><br /><br />
</form>

我希望这是有道理的——任何人都可以阐明如何让它发挥作用吗?

4

2 回答 2

0

我假设您没有发布完整的代码,因为您#clientDirectory#/#clientFile#在上面的代码中似乎没有源代码。

我整理了一个可能的样本,看看它可能是什么样子。为了便于阅读,我还将您的上传例程从代码主体移到了顶部。

<CFIF IsDefined("form.upload_now")>
    <CFIF structKeyExists(form, "ul_path") and len(form["ul_path"])>

        <!--- assuming you need to lookup info from the database --->   
        <cfquery name="getThisLocation">
            SELECT FolderID, FolderName, dir 
            FROM Locations
            where foldername=#form.folderid#

        </cfquery>      


        <CFFILE ACTION="UPLOAD" FILEFIELD="ul_path" 
                    DESTINATION="C:\Documents\#getThisLocation.dir#\"         
                    NAMECONFLICT="OverWrite">

        <CFSET ClientFilePath = "#getThisLocation.clientDirectory#\##getThisLocation.clientFile#">

     </CFIF>
</CFIF>


<cfquery name="getLocation">
    SELECT *
    FROM Locations
    ORDER BY FolderName
</cfquery>

<form action="docuploads.cfm" method="POST" enctype="multipart/form-data" name="upload_form" id="upload_form"> 

<CFIF IsDefined("form.upload_now")>
    <CFIF structKeyExists(form, "ul_path") and len(form["ul_path"])>
    <P>FILE UPLOADED</P>
    </CFIF>
</CFIF>

    <select name="folderID">
        <option value="">--- Select Folder ---</option>
        <cfoutput query="getLocation">
            <option value="#FolderName#"">#FolderName#</option>
        </cfoutput>
    </select>



     <br /><br />
     Click on the Browse button to select the file to Upload:<br>
     <input type="file" name="ul_path" id="ul_path" style="height: 22px;width: 350px;" value=""><br><br>
     <input type="submit" name="upload_now" id="upload_now" value="Submit" style="height: 22px;">
     <input type="button" name="clear" value="Clear" style="height: 22px;">
     <br /><br /><br />
</form>

我还添加了一段代码,让用户知道文件已上传。

于 2013-04-26T19:34:50.030 回答
-1

请试试这个:

<CFIF IsDefined("form.upload_now")>
      <CFIF structKeyExists(form, "ul_path") and len(form["ul_path"])>
         <CFFILE ACTION="UPLOAD" FILEFIELD="#form.ul_path#" 
                DESTINATION="C:\Documents\#dir#\"         
                NAMECONFLICT="OverWrite">
          <CFSET ClientFilePath = "#clientDirectory#\#clientFile#">
      </CFIF>
      <cfoutput>file uploaded successfully</cfoutput>
  </CFIF>

<cfquery name="getLocation">
  SELECT *
  FROM Locations
  ORDER BY FolderName
</cfquery>

<form action="docuploads.cfm" method="POST" enctype="multipart/form-data" name="upload_form" id="upload_form"> 
  <select name="folderID">
    <option value="">--- Select Folder ---</option>
    <cfoutput query="getLocation">
        <option value="#FolderName#"">#FolderName#</option>
    </cfoutput>
</select>

  <br /><br />
 Click on the Browse button to select the file to Upload:<br>
 <input type="file" name="ul_path" id="ul_path" style="height: 22px;width: 350px;" value=""><br><br>
 <input type="submit" name="upload_now" id="upload_now" value="Submit" style="height: 22px;">
 <input type="button" name="clear" value="Clear" style="height: 22px;">
 <br /><br /><br />

于 2013-04-30T11:09:17.897 回答