Copy link to clipboard
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))>
<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
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
...Copy link to clipboard
Copied
I think it has to be a fully-qualified filesystem path:
c:\directory\subdirectory\
Dave Watts, Fig Leaf Software
Copy link to clipboard
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,
^ _ ^
Copy link to clipboard
Copied
sorry, how exactly would that look in the destination part of the coldfusion code?
Copy link to clipboard
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.
Copy link to clipboard
Copied
my web server gives me this error
java.io.FileNotFoundException: D:\WWWRoot\mymindsnotright.com\www\uploads\madness2.jpg (Access is denied)
Copy link to clipboard
Copied
like, would it look like
<cfset thisPath=ExpandPath("*.*")>
destination="\uploads(thisPath)"
Copy link to clipboard
Copied
No.
<cfset thisPath = ExpandPath('.') />
destination = "#thisPath#\uploads"
HTH,
^ _ ^
Copy link to clipboard
Copied
is there a way to add a username and password into cffile?
Copy link to clipboard
Copied
You don't need a username and password. You need to know how the file structure is on the host server.
From the root of your site, where is the uploads folder? Is it www.yoursite.com/uploads? Is it www.yoursite.com/another/folder/then/uploads?
Copy link to clipboard
Copied
yes
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
or what information do i need from my web host in able to do this?
Copy link to clipboard
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.
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,
^ _ ^
Copy link to clipboard
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:
| |
The error occurred in D:/WWWRoot/mymindsnotright.com/www/Application.cfc: line 8 | |
6 : </cfcomponent> 7 : 8 : <cfset rootPath = "#REreplaceNoCase(ExpandPath('./'),'(.+[\\|\/]mymindsnotright.com\www)(.)+','\1','all')#" /> |
Copy link to clipboard
Copied
That means that something replaced my < with < in the process, somewhere.
Copy link to clipboard
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
Copy link to clipboard
Copied
i don't have an onrequestart part of my application.cfc where do i learn how to add it?
Copy link to clipboard
Copied
<cffunction name="onRequestStart">
<cfset rootPath = "#REreplaceNoCase(ExpandPath('./'),'(.+[\\|\/]mymindsnotright.com\www)(.)+','\1','all')#" />
</cffunction>
Goes between the </cfscript> and </cfcomponent> tags.
Copy link to clipboard
Copied
ok i fixed that in the applicatino.cfc but I still get this error when i make destination="#variables.rootPath#\uploads"
java.io.FileNotFoundException: D:\WWWRoot\mymindsnotright.com\www\uploads\manic2.jpg (Access is denied)
Copy link to clipboard
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.
Copy link to clipboard
Copied
do i need to get some kind of information from my web host or am i out of luck here?
Copy link to clipboard
Copied
wycks wrote
do 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.
Copy link to clipboard
Copied
yeah it still gives me:
java.io.FileNotFoundException: D:\WWWRoot\mymindsnotright.com\www\uploads\manic2.jpg (Access is denied)
i can't tell you how much I appreciate all the help you've given me today​