Skip navigation
btvbillb
Currently Being Moderated

How to cffileupload and store file paths in a database?

Mar 8, 2012 9:52 AM

I'm using CF 9 and have multi-file uploading working. What I need help with is a help desk type page that will display the filenames with links to the files that are uploaded with the form that a user submits. When I view an admin page, I need to see the email form results with a list of the files uploaded and links to where they are.

Any ideas on how I can get an admin page to display only the files associated with each form submission? I'm assuming that I need to find a method of stroring each uploaded file path to a database but I don't know how to do that. Any help would be appreciated. Thanks

 
Replies
  • Currently Being Moderated
    Mar 8, 2012 2:22 PM   in reply to btvbillb

    To store a file path in a database table treat the path as a string, normally a VARCHAR column in a database.  You can associate these database records with a tech support incident.  Just INSERT a record for each file to be stored.

     

    To download the file supply the file's path to CFCONTENT.

     

    References:

     

    CFCONTENT

    http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461 172e0811cbec22c24-7c82.html

     

    http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859 461172e0811cbec1553c-7feb.html

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 10, 2012 3:48 AM   in reply to btvbillb

    You could proceed as follows:

     

    1) Create a database table named uploadedFile. The columns could be, for example,

     

    upload_id: INT, autoincrement, primary key

    datetimecreated: DATETIME

    serverfile: VARCHAR(50)

    serverdirectory: VARCHAR(30)

     

    2) Do your multi-upload, for example,

     

    myMultiUploader.cfm

    <cffileupload url="myUploadFiles.cfm" width="600" ... etc>

     

    myUploadFiles.cfm

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

    <!--- This is where your question gets answered --->   

    <!--- All the information about each uploaded file is stored in the cffile structure. ColdFusion creates one cffile struct for each and every file you upload in a single upload round --->

    <!--- Save the information about each file to the database. The back slash \ often serves the purpose of an escape character. So I've replaced it with the forward slash / in the file path. --->

     

    <cfquery name="saveUploadInfo" datasource="myDSN">

        insert into uploadedfile (datetimecreated, serverdirectory, serverfile)

        values (#cffile.timecreated#, '#replace(cffile.serverdirectory,"\","/","all")#', '#cffile.serverfile#')

    </cfquery>

     

    <!--- You could in fact log (and review) all the upload data by means of the following --->

    <!--- <cflog file="uploadData" text="#serializeJson(cffile)#"> --->

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 13, 2012 1:55 AM   in reply to btvbillb

    btvbillb wrote:

     

    To display my uploaded files on a page where the files can appear as links or be deleted, how would I get only the uploaded files to display for each record in the database?

    For example, make sure the upload directory is under the web root, something like: c:\ColdFusion9\wwwroot\myUploads. then you've already solved half the problem. The rest can proceed as follows (using my query above as example)

     

    <cfquery name="getUploadFiles" datasource="myDSN">

        select serverfile

        from uploadedfile

        where datetimecreated > #some_datetime_value#

    </cfquery>

     

    List of links: <br>

    <cfif getUploadFiles.recordcount GT 0>

    <cfoutput query="getUploadFiles" >

    http://127.0.0.1:8500/myUploads/#serverfile#<br>

    </cfoutput>

    </cfif>

     

    Also, where would the log file "uploadData" log file be created/generated?

    c:\ColdFusion9\logs

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points