Skip to main content
Inspiring
August 2, 2018
Answered

cffile

  • August 2, 2018
  • 1 reply
  • 3692 views

Hi,

Sorry if this is a dumb question, I'm new to this.

I have a form where i want the user to be able to upload an image from a form.  for the cffile i'm using

<cfif len(trim(form.ImageData))>

  <cffile action="upload"

     fileField="ImageData"

     destination="\uploads"

     nameConflict = "MakeUnique">

</cfif>

it works locally when i input the specific directory on my hard drive but when i use the above online i get an access denied error and it looks like it's trying to save it locally on c:\uploads

on my ftp i created an upload folder but I don't know what the 'destination' field typically looks like when you are trying to use cffile on a live site.  What information do i need from my web host to make this work? Like, does it involve an ip address?  I'm thinking some kind of username and password will be required.  does cffile have username password field too?  Basically, what shoudl cffile look like when you're using it ion a  live site

Thanks,

MIke

    This topic has been closed for replies.
    Correct answer WolfShade

    or what information do i need from my web host in able to do this?


    Here.. let's make this foolproof.  In your sites root folder, open the application.cfc, find the onRequestStart section and add the following:

    <cfset rootPath = "#REreplaceNoCase(ExpandPath('./'),'(.+[\\|\/]mymindsnotright.com\www)(.)+','\1','all')#" />

    This line will create a variable called rootPath, and no matter where in the folder structure the user goes, rootPath will always point to the root of the site.

    Then, depending upon where in your site the uploads folder is, you append that flow to the variable rootPath.

    If it's /uploads, then the destination will be "#variables.rootPath#\uploads".

    If it's /another/folder/uploads, then destination will be "#variables.rootPath#\another\folder\uploads".

    HTH,

    ^ _ ^

    1 reply

    Community Expert
    August 2, 2018

    I think it has to be a fully-qualified filesystem path:

    c:\directory\subdirectory\

    Dave Watts, Fig Leaf Software

    Dave Watts, Eidolon LLC
    WolfShade
    Legend
    August 2, 2018

    Indeed, it does.  You need to put the full path from either the drive letter (C:\path\to\upload) on a Windows server, or /path/to/upload for a *nix server.  No relative paths allowed.

    So, you could use ExpandPath('/') to find the current folder, and go from there.

    V/r,

    ^ _ ^

    wycksAuthor
    Inspiring
    August 2, 2018

    sorry, how exactly would that look in the destination part of the coldfusion code?