Skip to main content
October 3, 2008
Answered

cffile upload

  • October 3, 2008
  • 7 replies
  • 832 views
Is there a way to capture the path of a file prior to performing cffile upload? I have the following tag on my site:

<cffile action="upload" filefield="user_file" destination="mydir/" nameconflict="makeunique">

I need to have makeunique set because a ton of files come in everyday and I can't have people overwriting. However, I do want to try to eliminate dupes so I want to store the original path, then skip the cffile tag if that exact file from the exact user already exists.
    This topic has been closed for replies.
    Correct answer Newsgroup_User
    idesdema wrote:
    > Thanks Ian for the process flow. Well written. I'm wondering about the
    > ServerFileExt... Is there something similar for the prefix of the file (or the
    > part that comes before the extension)?
    >
    > If there is, does that read in the string before or after the upload?
    >

    If you are asking is there a variable with the original file name, then
    yes. If you dump the cffile structure, there are values for the
    original file name, original file extension the server file name the
    server extension and more.

    7 replies

    October 3, 2008
    I always get my coldfusion knowledge in the worst way! Wait until I can't do something, then figure out how.

    http://livedocs.adobe.com/coldfusion/6/CFML_Reference/Tags-pt129.htm
    October 3, 2008
    That is what I am asking in a roundabout way. :)

    Yes I need that variable. I'll dump the file.ServerFile info and see that that does for me. Thanks!
    Newsgroup_UserCorrect answer
    Inspiring
    October 3, 2008
    idesdema wrote:
    > Thanks Ian for the process flow. Well written. I'm wondering about the
    > ServerFileExt... Is there something similar for the prefix of the file (or the
    > part that comes before the extension)?
    >
    > If there is, does that read in the string before or after the upload?
    >

    If you are asking is there a variable with the original file name, then
    yes. If you dump the cffile structure, there are values for the
    original file name, original file extension the server file name the
    server extension and more.
    October 3, 2008
    Thanks Ian for the process flow. Well written. I'm wondering about the ServerFileExt... Is there something similar for the prefix of the file (or the part that comes before the extension)?

    If there is, does that read in the string before or after the upload?
    October 3, 2008
    Well in this case they are images so they shouldn't be doing any editing after the first upload. Otherwise I'm with you on the replacing.

    The reason I want to prevent duplicate uploads is because once an image is uploaded I run a cfc on it that chews on the memory a bit.
    October 3, 2008
    I've only been able to get this to work in IE.. it will not work in FF.. just write a js function to pull out the value of the file field..

    By the way, just curious... but what happens when your users edit their documents/files and try and re-upload them? You should probably replace them instead of not allowing them to upload the file.

    example below:
    Inspiring
    October 3, 2008
    idesdema wrote:
    > Is there a way to capture the path of a file prior to performing cffile upload?

    Nope, not with a normal web application using the HTTP protocol. For
    very good security reasons the server know absolutely *NOTHING* about
    the clients file system.

    If one could get such information, such as the file path on the client
    system, one could do very nasty things to poor unsuspecting users.

    It helps me to think about the actual file upload process and what each
    piece of software does with it.

    1) The browser provides a control that lets a user manually *AND ONLY*
    manually select a file. It then encodes this file into a character
    encoding and submits this encoded block of data to the web server.

    2) I'll skip all what happens at the TCP/IP levels to get this data from
    the client to the server.

    3) The web server receives a request with a block of character data that
    it is told is a file. It decodes the data back into a file and stores
    this in it's defined temporary space. If it has been configured to do
    so, it then tells an application server -- ColdFusion is the favorite of
    this list -- about this file it received.

    4) The application server -- ColdFusion as I said -- gets the file from
    the temporary location and does what it has been instructed to do with it.

    But as you can see from deconstructing the communications ColdFusion is
    long removed from the client and has no idea where the file came from.