# cffile

Explorer ,
Aug 02, 2018 Aug 02, 2018

Copied

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))>

fileField="ImageData"

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

Views

1.5K

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

LEGEND , Aug 02, 2018 Aug 02, 2018
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 t...

Likes

39 Replies 39
Aug 02, 2018 Aug 02, 2018

Copied

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

c:\directory\subdirectory\

Dave Watts, Fig Leaf Software

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
LEGEND ,
Aug 02, 2018 Aug 02, 2018

Copied

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,

^ _ ^

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Aug 02, 2018 Aug 02, 2018

Copied

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

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
LEGEND ,
Aug 02, 2018 Aug 02, 2018

Copied

<cfif len(trim(form.ImageData))>  <cffile action="upload"    fileField="ImageData"    destination="#ExpandPath('/')#\uploads"    nameConflict = "MakeUnique"></cfif>

This should work.

HTH,

^ _ ^

UPDATE: This will work IF the uploads folder is in the folder that the action page is in.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Aug 02, 2018 Aug 02, 2018

Copied

my web server gives me this error

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Aug 02, 2018 Aug 02, 2018

Copied

like, would it look like

<cfset thisPath=ExpandPath("*.*")>

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
LEGEND ,
Aug 02, 2018 Aug 02, 2018

Copied

No.

<cfset thisPath = ExpandPath('.') />

HTH,

^ _ ^

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Aug 02, 2018 Aug 02, 2018

Copied

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
LEGEND ,
Aug 02, 2018 Aug 02, 2018

Copied

You don't need a username and password.  You need to know how the file structure is on the host server.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Aug 02, 2018 Aug 02, 2018

Copied

yes

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Aug 02, 2018 Aug 02, 2018

Copied

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Aug 02, 2018 Aug 02, 2018

Copied

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Aug 02, 2018 Aug 02, 2018

Copied

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

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
LEGEND ,
Aug 02, 2018 Aug 02, 2018

Copied

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.

HTH,

^ _ ^

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Aug 02, 2018 Aug 02, 2018

Copied

so after i added that to applicaiton.cfc i get this error

 ColdFusion was looking at the following text:<The CFML compiler was processing:< marks the beginning of a ColdFusion tag.Did you mean LT or LTE? The error occurred in D:/WWWRoot/mymindsnotright.com/www/Application.cfc: line 8 6 : 7 : 8 :

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
LEGEND ,
Aug 02, 2018 Aug 02, 2018

Copied

That means that something replaced my < with &lt; in the process, somewhere.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 02, 2018 Aug 02, 2018

Copied

That looks like you've messed up the structure for Application.cfc. You can't have anything after the closing cfapplication tag.

Dave Watts, Fig Leaf Software

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Aug 02, 2018 Aug 02, 2018

Copied

i don't have an onrequestart part of my application.cfc   where do i learn how to add it?

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
LEGEND ,
Aug 02, 2018 Aug 02, 2018

Copied

<cffunction name="onRequestStart">

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

</cffunction>

Goes between the </cfscript> and </cfcomponent> tags.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Aug 02, 2018 Aug 02, 2018

Copied

ok i fixed that in the applicatino.cfc but I still get this error when i make  destination="#variables.rootPath#\uploads"

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 02, 2018 Aug 02, 2018

Copied

Dave meant "closing cfcomponent", of course. But I see that Wolf has also sorted that out with you in a later note.

If all this doesn't work (you point to the right path and STILL can't write to it), that will be yet another problem, about permissions. I'll share a separate note about that in a moment.

/Charlie (server troubleshooter, carehart.org)

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Aug 02, 2018 Aug 02, 2018

Copied

do i need to get some kind of information from my web host or am i out of luck here?

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
LEGEND ,
Aug 02, 2018 Aug 02, 2018

Copied

 wycks  wrotedo i need to get some kind of information from my web host or am i out of luck here?

I would definitely contact tech support and ask them why access is denied.  That shouldn't be happening, unless they deny it for security purposes (as Charlie has pointed out).  In which case, they might have another folder for uploads.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Aug 02, 2018 Aug 02, 2018

Copied

yeah it still gives me: