0

我在将图像的文件名上传或循环到我的数据库表时遇到问题。

我可以选择各种图像并将本地计算机上的选定图像上传到我指定的特定文件夹。将图像文件放入我的文件夹后,我遇到了一些困难,因为我想将刚刚插入文件夹的图像的文件名插入到我的数据库中。我正在尝试使用 cffile 参数来做到这一点。

我的问题:由于一次上传多个文件,我是否需要在 cfquery insert 上执行 cfloop 才能捕获名称并将其插入到我的数据库中?我对代码的尝试如下。上传工作得很好,但它在插入部分窒息。你认为可能是什么问题?

<cfparam name="form.fileUpload3" default="">
<cfif len(trim(form.fileUpload3))>
   <cffile action="uploadall" 
      fileField="fileUpload3" 
      destination="#cookie.c.webpathmultipleimages#" 
      accept = "image/jpeg, image/png, image/jpeg" 
      nameconflict="makeunique">

   <!---This is where i'm running into my issue--->
   <cfloop INDEX="i" LIST="#Form.fileUpload3#">
      <cfquery name="addtoimage">
         insert into image (imaid, imacomid, imaname) 
         Value (
           '00',
          '#cookie.communityID#',
          '#file.clientfile#'
         )
      </cfquery>
</cfif>
4

1 回答 1

0

cffile 返回一个数组,但您使用了列表循环。所以,你得到了错误。尝试使用数组循环。

<cfif len( form.image )>
    <cffile action="uploadall" filefield="image" 
        destination="#ExpandPath('.\uploadImages\')#" 
        result="fileName" 
        nameconflict="makeunique">
    <cfloop array="#fileName#" index="image">
        <cfquery name="imageUpload" datasource="uploadMultipleImage">
            insert into uploadImage (imageName) 
            values 
            ( 
               <cfqueryparam value="#image.serverfile#" cfsqltype="cf_sql_varchar">
            )
        </cfquery>
    </cfloop>
</cfif>
于 2019-09-24T14:40:48.747 回答