School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,475 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,749 people online right now. Registration is fast and FREE... Join Now!




Access files outside of web root

 

Access files outside of web root, Coldfusion script to call files outside of web root?

midasxl

17 Apr, 2009 - 08:34 AM
Post #1

D.I.C Head
**

Joined: 3 Dec, 2008
Posts: 125



Thanked: 1 times
My Contributions
Hello and thanks for your time. I am using fusebox to create a coldfusion application. I have been asked to move certain files outside (above) the web root so they are not accessible via the web browser. I can no longer directly link to them, which is the point.

Is there a coldfusion script that can do this? I still want to get to them, but considering where they are now residing I do not know how to do that. If anyone can point me in the right direction, that would be wonderful! Not looking for any code at this point, just some direction. Thank you!

User is offlineProfile CardPM
+Quote Post


sansclue

RE: Access Files Outside Of Web Root

17 Apr, 2009 - 09:28 AM
Post #2

D.I.C Regular
***

Joined: 21 Nov, 2007
Posts: 316



Thanked: 28 times
My Contributions
Look into using cfcontent. It is often used to serve up documents from a protected area.
User is offlineProfile CardPM
+Quote Post

midasxl

RE: Access Files Outside Of Web Root

20 Apr, 2009 - 07:38 AM
Post #3

D.I.C Head
**

Joined: 3 Dec, 2008
Posts: 125



Thanked: 1 times
My Contributions
QUOTE(sansclue @ 17 Apr, 2009 - 09:28 AM) *

Look into using cfcontent. It is often used to serve up documents from a protected area.


Sansclue,
Thanks for the info. I have researched and implemented cfcontent. I have placed all sensitive documents above the web root and then created an actionpage to target them in their new location.

I'm using fusebox to create this app. Not sure if you are familiar with it. Actions are basically targeted using the url

CODE

<a href="https://xxx.xx.xxx.xxx/index.cfm?fuseaction=catControl.getFile" target="_blank">


getFile then has a fuseaction that points to a coldfusion action page (a fuse) that does the work. It's an interesting way to create an app.

I'm trying to pass variables in the query string, but it does not seem to like it. Here's what I am doing...

CODE

< a href="https://xxx.xx.xxx.xxx/index.cfm?fuseaction=catControl.getFile & data=#filePath#" target="_blank">


On the other end, the actionpage when processed give me an error that filePath is undefined. I ran a cfdump on the page that has the above link and the filePath returns a positive path to the file.

Am I appending the url properly to pass the variable? I've tried several combinations but I cannot seem to get it right. Thanks for any help you may be able to provide.

Cheers!


User is offlineProfile CardPM
+Quote Post

midasxl

RE: Access Files Outside Of Web Root

20 Apr, 2009 - 08:47 AM
Post #4

D.I.C Head
**

Joined: 3 Dec, 2008
Posts: 125



Thanked: 1 times
My Contributions
QUOTE

On the other end, the actionpage when processed give me an error that filePath is undefined. I ran a cfdump on the page that has the above link and the filePath returns a positive path to the file.

Am I appending the url properly to pass the variable? I've tried several combinations but I cannot seem to get it right. Thanks for any help you may be able to provide.


OK, on the action page when I reference the passed variable I am successfully using #URL.data# instead of just #data# and it seems to work fine. In other situations I have used the latter and it has worked fine. Perhaps this has something to do with the fact that I am using Fusebox to build this app.

Cheers!!
User is offlineProfile CardPM
+Quote Post

sansclue

RE: Access Files Outside Of Web Root

20 Apr, 2009 - 02:49 PM
Post #5

D.I.C Regular
***

Joined: 21 Nov, 2007
Posts: 316



Thanked: 28 times
My Contributions
QUOTE(midasxl @ 20 Apr, 2009 - 08:47 AM) *

index.cfm?fuseaction=catControl.getFile & data=#filePath#" ...


No, it just has the wrong parameter name. The syntax is:

paramterName=parameterValue

So if want it to be called "filePath", use that name instead of "data".

... &filePath=#filePath#"...>



This post has been edited by sansclue: 20 Apr, 2009 - 02:50 PM
User is offlineProfile CardPM
+Quote Post

Art_web

RE: Access Files Outside Of Web Root

21 Apr, 2009 - 09:48 AM
Post #6

New D.I.C Head
*

Joined: 18 Apr, 2009
Posts: 10

sorry, cant help...

blink.gif
User is offlineProfile CardPM
+Quote Post

midasxl

RE: Access Files Outside Of Web Root

22 Apr, 2009 - 05:17 AM
Post #7

D.I.C Head
**

Joined: 3 Dec, 2008
Posts: 125



Thanked: 1 times
My Contributions
QUOTE(sansclue @ 20 Apr, 2009 - 02:49 PM) *

QUOTE(midasxl @ 20 Apr, 2009 - 08:47 AM) *

index.cfm?fuseaction=catControl.getFile & data=#filePath#" ...


No, it just has the wrong parameter name. The syntax is:

paramterName=parameterValue

So if want it to be called "filePath", use that name instead of "data".

... &filePath=#filePath#"...>


Sansclue, thanks again. I was giving you the wrong information. This is how I have the URL...
CODE

index.cfm?fuseaction=catControl.getFile & data=#filePath#"


So I tried referencing #data# in the action page. This does not work unless I use #URL.data#

User is offlineProfile CardPM
+Quote Post

sansclue

RE: Access Files Outside Of Web Root

22 Apr, 2009 - 05:57 AM
Post #8

D.I.C Regular
***

Joined: 21 Nov, 2007
Posts: 316



Thanked: 28 times
My Contributions
QUOTE(midasxl @ 22 Apr, 2009 - 05:17 AM) *

So I tried referencing #data# in the action page. This does not work unless I use #URL.data#


Then use #url.data# ;-) It is the correct and it is better to scope your variables like that anyway. ie Use #scopename.variablename# instead of just #variablename#.



User is offlineProfile CardPM
+Quote Post

midasxl

RE: Access Files Outside Of Web Root

27 Apr, 2009 - 08:01 AM
Post #9

D.I.C Head
**

Joined: 3 Dec, 2008
Posts: 125



Thanked: 1 times
My Contributions
Thanks Sansclue. Here's what I ended up doing...

Here's a URL example
CODE

<a href="index.cfm?fuseaction=catModel.getFile & file='share/local/name_of_file.txt'"


Then fusebox would map to the appropriate action page which is the following...
CODE

<!---This will extract the right 3 characters from the variable #URL.file#, thus getting the file extension--->
<cfset type = Right(#URL.file#,3)>

<cfswitch expression = "#type#">
     <cfcase value="txt">
          <cfcontent type="text/plain"
          file="#request.fileArea##URL.file#"
          deletefile="no">
     </cfcase>
     <cfcase value="doc">
          <cfcontent type="application/msword"
          file="#request.fileArea##URL.file#"
          deletefile="no">
     </cfcase>

etc, etc. for more mime types
</cfswitch>


This works great!

Cheers!

This post has been edited by midasxl: 27 Apr, 2009 - 08:05 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 03:16AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month