Skip to main content
Participant
April 13, 2010
Question

Help!

  • April 13, 2010
  • 1 reply
  • 1081 views

Hi, I just got started in coldfusion and have coldfusion builder 9. I am using FlashBuilder 4 also. I want to make a file upload and don't know how. I would like to use coldfusion to specify how big the file can be and how many can be in the file upload folder.

    This topic has been closed for replies.

    1 reply

    BKBK
    Community Expert
    Community Expert
    April 13, 2010

    make a file upload

    specify how big the file can be

    and how many can be in the file upload folder.

    I find it a challenging, and useful, exercise. Here is an example in Coldfusion 9. There are 2 CFM files, multiUpload.cfm and uploadFiles.cfm, within the same directory.

    The maximum allowed file size for upload is 2 MB. The maximum number of files that can be uploaded each time is 10.

    My upload directory is c:\uploads. It has a limit of 30 files. When the  limit is reached, the upload button will disappear.

    multiUpload.cfm

    <cfset MAXUPLOADDIRSIZE = 30>
    <cfset isUploadButtonHidden = false>
    <cfset maxNoOfFilesSelectedForUpload = 10>

    <!--- list the upload dir --->
    <cfdirectory action="list" directory="c:\uploads" name="uploadDir">

    <cfset noOfFilesinUploadDir = uploadDir.recordcount>

    <p>
    <cfoutput>
    The upload directory currently has #noOfFilesinUploadDir# files.<br>
    The limit is #MAXUPLOADDIRSIZE#.<br>
    </cfoutput>
    </p>
    <br>

    <p>
    To show the current status of the upload folder, you must <a href="javascript:location.reload(true);" title="Refresh page">refresh this page</a> after every upload.
    </p>
    <br>

    <cfset uploadFolderAllowance = MAXUPLOADDIRSIZE - noOfFilesinUploadDir>
    <cfif uploadFolderAllowance LTE 0>
        <cfset isUploadButtonHidden = true>
        <cfset maxNoOfFilesSelectedForUpload = 0>
    <cfelseif uploadFolderAllowance LTE 10>
        <cfset maxNoOfFilesSelectedForUpload = uploadFolderAllowance>
    </cfif>

    <cffileupload 
        url="uploadFiles.cfm"
        maxuploadsize="2"
        hideUploadButton = "#isUploadButtonHidden#"
        progressbar="true"
        name="myupload"
        addButtonLabel = "Add File"
        clearButtonlabel = "Clear"
        uploadButtonlabel="Upload"
        width=600
        height=400
        title = "File Upload"  
        maxFileSelect="#maxNoOfFilesSelectedForUpload#" />

    uploadFiles.cfm

    <cffile 
        action = "uploadAll"
        destination = "c:\uploads"
        nameConflict = "overwrite">

    mroilerAuthor
    Participant
    April 14, 2010

    In FlashBuilder, which ColdFusion file would I direct it to? Also what script do I use use in FlashBuilder and what ColdFusion code can I use to be able to delete files and show them in FlashBuilder?

    mroilerAuthor
    Participant
    April 24, 2010

    I just found out I can't use ColdFusion! My hosting plan doesn't support ColdFusion! Thanks Anyway!