Copy link to clipboard
Copied
i find this really complicated. i got a flashpage that uploads images. In fact for each image selected, it uploads 3 different formats (thumb_, midle_, max_)
So I upload image1.jpg and I get thumb_image1.jpg, middle_image1jpg, and max_image1.jpg
I can upload unto 9 images at at time, they will all have these three formats.
After uploading data get posted to the last file where I need to rename files and write them to db
The data that get's posted has the format:
MPuploadFileName_0 = sea.jpg
MPuploadFileName_1 = sea1.jpg
MPuploadFileName_3 = sea2.jpg
etc.
Dont forget, each image has 3 formats. In fact the MPuploadFileName_0 is hte 'main' filename and the others are details of it.
Each file upload get's an ID from the DB (don't ask me why, I didn't invent the software just have to work with it:-)) So I get latest ID, add 1 and write for exemple 104256 to db
now system supposes there is a 104256_max.jp, 104256_middle.jpg, 104256_thumb.jpg
This was for the 'main image'
<cffile action="rename"
source="#request.site.imgupload#\#MPuploadFileName_0#_max"
destination="#request.site.imgupload#\#request.currentimgid#_max.jpg">
<cffile action="rename"
source="#request.site.imgupload#\middle_#MPuploadFileName_0#"
destination="#request.site.imgupload#\#request.currentimgid#_middle.jpg">
<cffile action="rename"
source="#request.site.imgupload#\thumb_#MPuploadFileName_0#"
destination="#request.site.imgupload#\#request.currentimgid#_thumb.jpg">
This works, that is already that
Now the more difficult, for the 'detail images' the system supposes they are called 104256_detail2_max.jpg, 104256_detail2_middle.jpg, 104256_detail2_max.jpg, 104256_detail3_max.jpg, 104256_detail3_middle.jpg, 104256_detail3_max.jpg, etc
The number of uploaded files is in a variable named "filecount"
So I have to turn MPuploadFileName_1 = sea1.jpg that has been uploaded as thumb_sea1.jpg, middle_sea1jpg, and max_sea1.jpg into
104256_detail2_max.jpg, 104256_detail2_middle.jpg, 104256_detail2_max.jpg
This is what I tried:
<cfloop from="1" to="#filesCount#" index="i">
<cfset ThisCurrentFileName = ["MultiPowUploadFileName_" & i] />
<cfset count = 2 />
<cfset ThisFileNametoChange = "thumb_"& ThisCurrentFileName />
<cfset ThisNewFileName = [request.currentimgid & "_detail" & teller & "_thumb.jpg"] />
<cffile action="rename"
source="#request.site.imgupload#\thumb_#ThisCurrentFileName#"
destination="#request.site.imgupload#\#thisNewFileName#">
<cfset ThisFileNametoChange = "middle_"& ThisCurrentFileName />
<cfset ThisNewFileName = [request.currentimgid & "_detail" & teller & "_middle.jpg"] />
<cffile action="rename"
source="#request.site.imgupload#\#ThisFileNametoChange#"
destination="#request.site.imgupload#\#thisNewFileName#">
<cfset ThisFileNametoChange = ["max_" & ThisCurrentFileName ] />
<cfset thisNewFileName = [request.currentimgid & "_detail" & teller & "_max.jpg"] />
<cffile action="rename"
source="#request.site.imgupload#\middle_#ThisCurrentFileName#"
destination="#request.site.imgupload#\#thisNewFileName#">
<cfset count = #count# + 1 />
</cfloop>
ERROR;
58 : <cfset ThisFileNametoChange = "thumb_"& ThisCurrentFileName />
I hope i explained it well, any help would be greatly appreciated.
Did you order the facepalm, sir? Spot the problem:
<cfset thisNewfilenamethumb = request.currentimgid & "_detail" & count & "_thumb.jpg">
<cfset thisNewfilenamemiddle = request.currentimgid & "_detail" & count & "_middle.jpg">
<cfset thisNewfilenamemax = request.currentimgid & "_detail" & count & "_max.jpg">
You're using the variable "count" rather than "idx". "Count" will always be 8, so it overwrites each previous file with the new one of the same name.
Copy link to clipboard
Copied
I thought I was almost there but now it get's even more weird, here's the code that is supposed to rename the images 1 by 1 to a number I get from database into "request.currentimgid". But what is happening, I upload 8 images, I verify all images are uploaded and the cfdump of the form gives me the name of each image. "count" is correct.
Then the following code runs and I end up with....... 3 files,
487700_detail8_max.jpg
487700_detail8_middle.jpg
487700_detail8_thumb.jpg
So the last uploaded file has been renamed correctly and the others..... gone away. I assure you, I checked they where in the directory before running this code, I checked with a cfdirectory and physically on the server.
<cfloop from="1" to="#count#" index="idx">
<cfset thisCurrentFileName = evaluate("MultiPowUploadFileName_" & idx) />
<cfset realFiletoRenamethumb = "thumb_" & thisCurrentFileName />
<cfset realFiletoRenamemiddle = "middle_" & thisCurrentFileName />
<cfset realFiletoRenamemax = "max_" & thisCurrentFileName>
<cfset thisNewfilenamethumb = request.currentimgid & "_detail" & count & "_thumb.jpg">
<cfset thisNewfilenamemiddle = request.currentimgid & "_detail" & count & "_middle.jpg">
<cfset thisNewfilenamemax = request.currentimgid & "_detail" & count & "_max.jpg">
<cfif FileExists('#request.site.imgupload#\#realFiletoRenamethumb#')>
<cffile action="rename"
source="#request.site.imgupload#\#realFiletoRenamethumb#"
destination="#request.site.imgupload#\#thisNewfilenamethumb#">
</cfif>
<cfif FileExists('#request.site.imgupload#\#realFiletoRenamemiddle#')>
<cffile action="rename"
source="#request.site.imgupload#\#realFiletoRenamemiddle#"
destination="#request.site.imgupload#\#thisNewfilenamemiddle#">
</cfif>
<cfif FileExists('#request.site.imgupload#\#realFiletoRenamemax#')>
<cffile action="rename"
source="#request.site.imgupload#\#realFiletoRenamemax#"
destination="#request.site.imgupload#\#thisNewfilenamemax#">
</cfif>
</cfloop>
Copy link to clipboard
Copied
Did you order the facepalm, sir? Spot the problem:
<cfset thisNewfilenamethumb = request.currentimgid & "_detail" & count & "_thumb.jpg">
<cfset thisNewfilenamemiddle = request.currentimgid & "_detail" & count & "_middle.jpg">
<cfset thisNewfilenamemax = request.currentimgid & "_detail" & count & "_max.jpg">
You're using the variable "count" rather than "idx". "Count" will always be 8, so it overwrites each previous file with the new one of the same name.
Copy link to clipboard
Copied
OEF, how stupid can one feel. I am a blond girl, that must be it. haha.
Thank you for not letting me down.
Bianca
Copy link to clipboard
Copied
If I got a quid for every time I'd made a rookie programming mistake I wouldn't need to write code any more ![]()
Copy link to clipboard
Copied
I am lucky, I have a boss that pays me for each hour I spent on it, I had to
implement it in an existing CMS written by someone else so it had to behave
exactly like it did that is why it became this complicated. If it would have
been my choise I would have just written each filename to the database.
Bianca
Copy link to clipboard
Copied
I am lucky, I have a boss that pays me for each hour I spent on it
Amazing, I do hope there's no upper limit on that. If you'd have said I could've purposely taken longer to reply for a cut of the profits.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more