Skip to main content
June 3, 2011
Question

help with array for beginner

  • June 3, 2011
  • 1 reply
  • 595 views

i am not good with arrays, I need to make an array from something posted by a flash image uploader.The posted information is

MultiPowUploadFileDate_0    1247547145650
MultiPowUploadFileName_2    Hydrangeas.jpg
filesCount    3
MultiPowUploadFileSize_0    879394
MultiPowUploadFileSize_1    845941
MultiPowUploadFileName_1    Desert.jpg
MultiPowUploadFileName_0    Chrysanthemum.jpg
MultiPowUploadFileStatus_2    2
MultiPowUploadFileDate_2    1247547145634
MultiPowUploadFileId_0    C4BA3C3A-09B8-3C10-1C01-39AD0B6E8FBA
MultiPowUploadFileStatus_1    2
MultiPowUploadFileId_2    3A6F0020-D916-2270-0ADC-C7DC6482B5F5
MultiPowUploadFileSize_2    595284
MultiPowUploadFileStatus_0    2
MultiPowUploadFileDescription_2  
MultiPowUploadFileDescription_0  
MultiPowUploadFileId_1    0DAF1163-44B6-8A62-FDEB-B3F4999A78D5
MultiPowUploadId    47DBFDC9-7366-1E4B-6220-A9C039E688D5
MultiPowUploadFileDescription_1  
MultiPowUploadFileDate_1    1247547145634


I need the array with the filenames from MultiPowUploadFileName_0 to 9
BUT each filename is uploaded in 3 versions <filename_thumb.jpg> <filename_middle.jpg> <filename_big.jpg>

I need this array in order to be able to rename the files and to store them one by one in a database.

any help would be greatly appreciated!

    This topic has been closed for replies.

    1 reply

    Owainnorth
    Inspiring
    June 3, 2011

    Not sure I follow, as far as I see, you're saying that a bunch of formfields are sent to a CF page for processing? Is it a fixed number or does it vary?

    As far as I can see, you have the following fields for each image:

    MultiPowUploadFileDate_

    MultiPowUploadFileSize_

    MultiPowUploadFileName_

    MultiPowUploadFileId_

    MultiPowUploadFileStatus_

    MultiPowUploadFileDescription_

    But the only one you need is MultiPowUploadFileName. If that's the case, you don't need an array at all, just a loop. Like so:

    <!--- Loop, assuming it's a known number of fields --->

    <cfloop from="1" to="9" index="i">

      <!--- Take advantage of CF's bracket notation to construct the form field name dynamically --->

      <cfset ThisCurrentFileName = FORM["MultiPowUploadFileName_" & i] />

      <!--- Use that string and insert it into your database --->

      <cfquery...>

       INSERT INTO whatever

       VALUES <cfqueryparam cfsqltype="cf_sql_varchar" value="#ThisCurrentFileName#" />

      </cfquery>

    </cfloop>

    Is that the kind of thing you're after? Or have I misunderstood? Not sure what you mean by the three image names though.

    June 3, 2011

    It is a CMS and for eachimage that is uploaded we need a tiny thumbnail,  a medium version and a big version, these versions are created  automatically by the flash component. So when it says  MultiPowUploadFileName_0 = image1.jpg, in fact it uploaded  image1_thumb.jpb, image1_medium.jpg and image1_big.jpg

    I need to rename then these names to a number that is incremented in the  database so we get 40125_thumb.jpg, 40125_medium.jpg, 40125_big.jpg

    I thought of doing that with cffile action="rename"

    The number of files varies but is 9 maximum, there is a variable that is posted "filecount" that tells me how many images there are.

    THe nice thing with this plugin I am using is that images are resized before uploading. Our clients are uploading hundreds of images. I started working on a CMS that has been '' invented' by someone else, I would never have invented that these images needed to have a number as filename:-)

    What you are saying about looping seems logic to me I am going to try.