• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Uploading the file names of my images to my database table

New Here ,
Sep 21, 2019 Sep 21, 2019

Copy link to clipboard

Copied

I'm having an issue with uploading or looping through the the file names of my images to my database table.

I am able to select various images and upload the selected image on my local machine to a specific folder that I designate. After the image files are put into my folder, I am having some difficulties because I want to insert the file names of the images that I just inserted into my folder, into my database. I'm trying to use the cffile parameters to do that.


My question: Being that it is multiple files being uploaded at once, do I need to do a cfloop on a  cfquery insert in order to capture and insert the names into my database? My attempt at the code is below. The upload work just fine. But It chokes out at the insert portion. What do you think could be the issue?

<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>
</cfloop>
</cfif>

 

Thanks for any help you can provide...

Views

158

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 23, 2019 Sep 23, 2019

Copy link to clipboard

Copied

LATEST

You have makeunique as an attribute on your cffile so remember that the file name they specify in the form may not be the one that actually makes it onto the file system.   In the case of a single upload cffile.serverFile would give you the name of the file actually on disk and cffile.clientFile would give you the name they uploaded.  I'd store both if it were me so you can know what it is they uploaded vs what it actually is on disk and have a mapping between the two.  Chances are it would likely be the same but better to be safe than sorry. 

 

Using uploadAll you are supposed to get back an array of structures with the file details so you'd then loop over that array, not the clientFiles like you have in your sample, and insert the clientName and the serverName into the db.  I'd do a dump of CFFILE, or specify a returnvariable name to use, so you can see how the data is structured and that should get you on the way to getting it all working.

 

Also i'd point you to a great page by Pete Freitag on security for file uploads in case you haven't seen it.  Lots of good tidbits in there to be aware of.

https://www.petefreitag.com/item/701.cfm

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation