Skip to main content
Participating Frequently
February 21, 2012
Question

how to get the full path of a file

  • February 21, 2012
  • 2 replies
  • 2144 views

    If the user selects a file through a browse button, Is there a way, I can get the full path of the file. The file can be from his local hard drive as well.. Can someone advise    

    This topic has been closed for replies.

    2 replies

    Inspiring
    February 21, 2012

    To upload multiple files (example is for 3), try something like this.

    == Form section ==

    There would be three(3) file form fields for the selection of a file/document to upload, which

    each being uniquely named.

    <div style="clear: both;">

    <cfinput type="file" name="upload_01" dir="ltr" lang="en" size="70" xml:lang="en">

    </div>

    <div style="clear: both;">

    <cfinput type="file" name="upload_02" dir="ltr" lang="en" size="70" xml:lang="en">

    </div>

    <div style="clear: both;">

    <cfinput type="file" name="upload_03" dir="ltr" lang="en" size="70" xml:lang="en">

    </div>

    == Processing section ==

    Checks to see if any files / documents were selected for upload. If none were, then

    displays an alert indicating as such. If at least one file/document was selected, then

    the process would process the upload.

    <cfif isdefined('form.upload_01') and trim(form.upload_01) eq "" and

    isdefined('form.upload_02') and trim(form.upload_02) eq "" and

    isdefined('form.upload_03') and trim(form.upload_03) eq ""

    >

        <p>Did not select any files to upload</p>

    <cfelse>

        <cfif isdefined('form.upload_01') and trim(form.upload_01) neq "">

            <cffile

                action="upload"

                destination="C:\path\to\upload\files\to"

                filefield="upload_01"

                nameconflict="overwrite"

                accept="

                  application/msword

                , application/vnd.openxmlformats-officedocument.wordprocessingml.document

                , application/vnd.ms-excel

                , application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

                , application/pdf">

                <cfcookie name="upload_01_doc" value="#cffile.serverfile#">

                <cfcookie name="upload_01_doc_ext" value="#cffile.serverfileext#">

        </cfif>

        <cfif isdefined('form.upload_02') and trim(form.upload_02) neq "">

            <cffile

                action="upload"

                destination="C:\path\to\upload\files\to"

                filefield="upload_02"

                nameconflict="overwrite"

                accept="

                  application/msword

                , application/vnd.openxmlformats-officedocument.wordprocessingml.document

                , application/vnd.ms-excel

                , application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

                , application/pdf">

                <cfcookie name="upload_02_doc" value="#cffile.serverfile#">

                <cfcookie name="upload_02_doc_ext" value="#cffile.serverfileext#">

        </cfif>

        <cfif isdefined('form.upload_03') and trim(form.upload_03) neq "">

        <cffile

            action="upload"

            destination="C:\path\to\upload\files\to"

            filefield="upload_03"

            nameconflict="overwrite"

            accept="

                  application/msword

                , application/vnd.openxmlformats-officedocument.wordprocessingml.document

                , application/vnd.ms-excel

                , application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

                , application/pdf">

            <cfcookie name="upload_03_doc" value="#cffile.serverfile#">

            <cfcookie name="upload_03_doc_ext" value="#cffile.serverfileext#">

        </cfif>

        <cflocation url="completed.cfm" addtoken="no">

    </cfif>

    == Completed section ==

    Can confirm to the person what files were actually uploaded, by displaying file name and file extension.

    You can you use the file extension information to display a respective icon for the file type.

    <cfoutput>

    <cfif isdefined('cookie.upload_01_doc')>

    01. #cookie.upload_01_doc# - #cookie.upload_01_doc_ext#<br /></cfif>

    <cfif isdefined('cookie.upload_02_doc')>

    02. #cookie.upload_02_doc# - #cookie.upload_02_doc_ext#<br /></cfif>

    <cfif isdefined('cookie.upload_03_doc')>

    03. #cookie.upload_03_doc# - #cookie.upload_03_doc_ext#<br /></cfif>

    </cfoutput>

    Leonard B

    February 23, 2012

    @Muthuraj_kv

    I hope you are using <cffile action="upload"> to upload file to the server.

    By doing this you can keep track of all information ragarding the upload just by <cfdump var="#fileupload#">

    If you want to check only path of the client file then <cfdump var="#fileupload.clientDirectory#">

    If you want to upload multiple files then use <cffile action="uploadAll">

    Owainnorth
    Inspiring
    February 21, 2012

    The full path of the file on their computer? No there is no way of getting that.

    Participating Frequently
    February 21, 2012

    I need to copy the file from the user selected place to a server location. Can you provide any suggestions    

    Owainnorth
    Inspiring
    February 21, 2012

    You use the <input type="file"> HTML tag, and the <cffile action="upload"> tag on the server. Google will reveal all.