Highlighted

Uploading multiple files in the same form

New Here ,
Jan 17, 2019

Copy link to clipboard

Copied

I am having a problem uploading multiple files at the same time. The site we are building is a catalog of sorts, and each item may have anywhere from 1-20 images.

For this discussion, let's say we're uploading three images

The input on the form creates three cffile tags in the form, named img1, img2, img3. Those are working.

After inputting the form, I see three distinct temp files. However, when the <cffile> tag runs, it only uploads the first file. Three times.

I created output that would show all of the variables, and the output shows the three distinct images, but then <cffile> runs and all of the server variables are correct for the first image, but shown three times.

Now, these file names also have to be written to a database, so I have to write the actual file name to the table, with time and date appended on it so that the file names are truly unique. Everything is working for the first file, it's the second and third that are the issue.

The code that generates the input tags:

<cfloop index="i" from="1" to="#imageCount#">

<cfoutput>

<tr>

    <td valign="top" rowspan="2">Image #i#</td>

        <td><cfif #i# is 1>This is the main photo for the item, and will show by default in the inventory.<br /></cfif><cfinput type="file" name="img#i#" id="img#i#" size="50" /></td>

    </tr>

    <tr>

    <td nowrap="nowrap">Description - <cfinput type="text" required="no" name="imgDesc#i#" message="Please enter text for image #i#" size="100" maxlength="100"> </td>

    </tr>

</td>

</cfoutput>

</cfloop>

The code that generates the output:

<cfloop index="i" from="1" to="#form.imageCount#">

<!--- make new file name --->

<cfset theFile = "img"&#i#>

    #theFile#<br />

    <cfset theFile = evaluate(theFile)>

    -the temp file - #theFile#<br />

    <!--- <cffile destination="#fileLocation#" file="#theFile#" action="upload" nameConflict="overwrite"> --->

    <!--- --->

    **cffile runs**<br />

     <cffile accept="image/jpeg" file="#theFile#" action="upload" destination="#fileLocation#" nameConflict="makeunique">

    

        --fileName - #CLIENTFILE#<br />

        --clientFileName - #clientFileName#<br />

        --file Location - #fileLocation#<br />

        --serverFileName - #serverFileName#<br />

        --serverFile - #serverFile#<br />

        --serverFileExt - #serverFileExt#<br />

       

       

        --date - #dateFormat(now(),"yyyymmdd")#<br />

        --time - #timeformat(now(),"HHMMSS")#<br />

       

        ---file on the server - #serverFile#<br />

        ---original file name - #CLIENTFILE#<br />

        ---rebuilt file name - #clientFileName#_#session.memberID#_#dateFormat(now(),"yyyymmdd")##timeformat(now(),"HHMMSS")#.#serverFileExt#<br />

<hr />

</cfloop>

And the output I see on the screen:

img1

-the temp file - C:\ColdFusion2018\cfusion\runtime\work\Catalina\localhost\tmp\neotmp13005993552846511814.tmp

**cffile runs**

--fileName - testImage1.jpg

--clientFileName - testImage1

--file Location - D:\home\elfquestinventory.com\wwwroot\images\uploaded

--serverFileName - testImage16

--serverFile - testImage16.jpg

--serverFileExt - jpg

--date - 20190117

--time - 142050

---file on the server - testImage16.jpg

---original file name - testImage1.jpg

---rebuilt file name - testImage1_1_20190117142050.jpg


img2

-the temp file - C:\ColdFusion2018\cfusion\runtime\work\Catalina\localhost\tmp\neotmp7930083167237002815.tmp

**cffile runs**

--fileName - testImage1.jpg

--clientFileName - testImage1

--file Location - D:\home\elfquestinventory.com\wwwroot\images\uploaded

--serverFileName - testImage17

--serverFile - testImage17.jpg

--serverFileExt - jpg

--date - 20190117

--time - 142050

---file on the server - testImage17.jpg

---original file name - testImage1.jpg

---rebuilt file name - testImage1_1_20190117142050.jpg


img3

-the temp file - C:\ColdFusion2018\cfusion\runtime\work\Catalina\localhost\tmp\neotmp2975829891593456969.tmp

**cffile runs**

--fileName - testImage1.jpg

--clientFileName - testImage1

--file Location - D:\home\elfquestinventory.com\wwwroot\images\uploaded

--serverFileName - testImage18

--serverFile - testImage18.jpg

--serverFileExt - jpg

--date - 20190117

--time - 142050

---file on the server - testImage18.jpg

---original file name - testImage1.jpg

---rebuilt file name - testImage1_1_20190117142050.jpg

Any input would be appreciated. I really do NOT want to have to have 20 individual inserts to get to all of the images, because that will be REALLY annoying for users.

Thanks,

Michelle

Views

297

Likes

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

Uploading multiple files in the same form

New Here ,
Jan 17, 2019

Copy link to clipboard

Copied

I am having a problem uploading multiple files at the same time. The site we are building is a catalog of sorts, and each item may have anywhere from 1-20 images.

For this discussion, let's say we're uploading three images

The input on the form creates three cffile tags in the form, named img1, img2, img3. Those are working.

After inputting the form, I see three distinct temp files. However, when the <cffile> tag runs, it only uploads the first file. Three times.

I created output that would show all of the variables, and the output shows the three distinct images, but then <cffile> runs and all of the server variables are correct for the first image, but shown three times.

Now, these file names also have to be written to a database, so I have to write the actual file name to the table, with time and date appended on it so that the file names are truly unique. Everything is working for the first file, it's the second and third that are the issue.

The code that generates the input tags:

<cfloop index="i" from="1" to="#imageCount#">

<cfoutput>

<tr>

    <td valign="top" rowspan="2">Image #i#</td>

        <td><cfif #i# is 1>This is the main photo for the item, and will show by default in the inventory.<br /></cfif><cfinput type="file" name="img#i#" id="img#i#" size="50" /></td>

    </tr>

    <tr>

    <td nowrap="nowrap">Description - <cfinput type="text" required="no" name="imgDesc#i#" message="Please enter text for image #i#" size="100" maxlength="100"> </td>

    </tr>

</td>

</cfoutput>

</cfloop>

The code that generates the output:

<cfloop index="i" from="1" to="#form.imageCount#">

<!--- make new file name --->

<cfset theFile = "img"&#i#>

    #theFile#<br />

    <cfset theFile = evaluate(theFile)>

    -the temp file - #theFile#<br />

    <!--- <cffile destination="#fileLocation#" file="#theFile#" action="upload" nameConflict="overwrite"> --->

    <!--- --->

    **cffile runs**<br />

     <cffile accept="image/jpeg" file="#theFile#" action="upload" destination="#fileLocation#" nameConflict="makeunique">

    

        --fileName - #CLIENTFILE#<br />

        --clientFileName - #clientFileName#<br />

        --file Location - #fileLocation#<br />

        --serverFileName - #serverFileName#<br />

        --serverFile - #serverFile#<br />

        --serverFileExt - #serverFileExt#<br />

       

       

        --date - #dateFormat(now(),"yyyymmdd")#<br />

        --time - #timeformat(now(),"HHMMSS")#<br />

       

        ---file on the server - #serverFile#<br />

        ---original file name - #CLIENTFILE#<br />

        ---rebuilt file name - #clientFileName#_#session.memberID#_#dateFormat(now(),"yyyymmdd")##timeformat(now(),"HHMMSS")#.#serverFileExt#<br />

<hr />

</cfloop>

And the output I see on the screen:

img1

-the temp file - C:\ColdFusion2018\cfusion\runtime\work\Catalina\localhost\tmp\neotmp13005993552846511814.tmp

**cffile runs**

--fileName - testImage1.jpg

--clientFileName - testImage1

--file Location - D:\home\elfquestinventory.com\wwwroot\images\uploaded

--serverFileName - testImage16

--serverFile - testImage16.jpg

--serverFileExt - jpg

--date - 20190117

--time - 142050

---file on the server - testImage16.jpg

---original file name - testImage1.jpg

---rebuilt file name - testImage1_1_20190117142050.jpg


img2

-the temp file - C:\ColdFusion2018\cfusion\runtime\work\Catalina\localhost\tmp\neotmp7930083167237002815.tmp

**cffile runs**

--fileName - testImage1.jpg

--clientFileName - testImage1

--file Location - D:\home\elfquestinventory.com\wwwroot\images\uploaded

--serverFileName - testImage17

--serverFile - testImage17.jpg

--serverFileExt - jpg

--date - 20190117

--time - 142050

---file on the server - testImage17.jpg

---original file name - testImage1.jpg

---rebuilt file name - testImage1_1_20190117142050.jpg


img3

-the temp file - C:\ColdFusion2018\cfusion\runtime\work\Catalina\localhost\tmp\neotmp2975829891593456969.tmp

**cffile runs**

--fileName - testImage1.jpg

--clientFileName - testImage1

--file Location - D:\home\elfquestinventory.com\wwwroot\images\uploaded

--serverFileName - testImage18

--serverFile - testImage18.jpg

--serverFileExt - jpg

--date - 20190117

--time - 142050

---file on the server - testImage18.jpg

---original file name - testImage1.jpg

---rebuilt file name - testImage1_1_20190117142050.jpg

Any input would be appreciated. I really do NOT want to have to have 20 individual inserts to get to all of the images, because that will be REALLY annoying for users.

Thanks,

Michelle

Views

298

Likes

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
Jan 17, 2019 0
LEGEND ,
Jan 17, 2019

Copy link to clipboard

Copied

I have tried writing code to upload multiple files only once.  It was a learning experience, I can tell you.

I asked about it a little over two years ago, for CF10.  I hope this will be able to help you.

https://forums.adobe.com/thread/2158602

HTH,

^ _ ^

Likes

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
Reply
Loading...
Jan 17, 2019 0
New Here ,
Jan 18, 2019

Copy link to clipboard

Copied

I had actually read through that thread yesterday before I posted.

It might work, but it seems awful painful. I just don't understand why the variables aren't changing and it's uploading the same file over and over. It seems like an issue actually IN ColdFusion itself. The three temp files are different, and it knows that three different files are there, but it only loads the information from the first.

Makes no sense!

Likes

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
Reply
Loading...
Jan 18, 2019 0
LEGEND ,
Jan 18, 2019

Copy link to clipboard

Copied

I see that you're using CF2018.  This could be a bug.  You could try reporting it to see if there's a fix.  The code I wrote was for CF10 and could be a workaround until such time as your issue is fixed.

V/r,

^ _ ^

Likes

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
Reply
Loading...
Jan 18, 2019 0