Solved

Security: The requested template has been denied access to D:\wwwroot.

Posted on 2011-09-21
8
325 Views
Last Modified: 2013-12-24
I am trying to create folders on a hosted website on the same level as the root. Testing internally I got this loop to work but I had all permissions.

On the hosted site I know I don't have permision for the level D:\wwwroot. I have permissions from our domain onwards which looks like this: D:\wwwroot\imailroom.ca.

How can I change the code below to start at our domain?
<cfset strCommonPath = "/" & "TestClient\iEnvelopes\" />  
<cfset strFileName = "testimage.jpg" />

<cfset strFilePath = "#expandPath('../../../')#imail_scans" />
<cfset DirectoryTree = Left(strFilePath, 2)>
<cfset strBareFilePath = "#replacenocase(strFilePath, DirectoryTree, "", 'all')#" />
<cfset strFullHostPath = strBareFilePath & replacenocase(strCommonPath, "/", "\", 'all') />
  
<!--- this creates folders if they do not exist on the web host site --->
<cfloop list="#strFullHostPath#" index="Directory" delimiters="\">
     <cfset DirectoryTree = ListAppend(DirectoryTree,Directory,"\")>

    <cfif DirectoryExists(DirectoryTree)> 
  <cfelse> 
     <cftry>
               <cfdirectory action="Create" directory="#DirectoryTree#"> 
          <cfcatch>
               <!--- Just let it loop --->
          </cfcatch>
     </cftry>
</cfif> 
</cfloop>

Open in new window

0
Comment
Question by:Shawn
  • 5
  • 3
8 Comments
 
LVL 39

Expert Comment

by:gdemaria
ID: 36577964

The root folder can be referred to using:     expandPath('/')

I am not sure which variable you want to set to that, but that will get you the full path to your root.
0
 
LVL 1

Author Comment

by:Shawn
ID: 36581888
yep, using expandpath. just a little confused. Code is improving...Now I manage to create folders in the root but not quite the way I want.

In the example below I am creating both the folders TestClient and iEnvelopes but they are both being created at the root whereas iEnvelopes is actually a subfolder of TestClient.

any idea what I'm doing wrong here?
<cfset strCommonPath = "TestClient\iEnvelopes\" />  
<cfset strFileName = "testimage.jpg" />

<cfset strFilePath = "#expandPath('../../../')#imail_scans" />
<cfset DirectoryTree = Left(strFilePath, 2)>


<cfset strBareFilePath = "#replacenocase(strFilePath, DirectoryTree, "", 'all')#" />
<cfset strFullHostPath = strBareFilePath & replacenocase(strCommonPath, "/", "\", 'all') />
  
<!--- this creates folders if they do not exist on the web host site --->
<cfloop list="#strCommonPath#" index="Directory" delimiters="\">
     <cfset DirectoryTree = ListAppend(strFilePath,Directory,"\")>
 
     <cfif DirectoryExists(DirectoryTree)> 
     <cftry>
               <cfdirectory action="Create" directory="#DirectoryTree#"> 
          <cfcatch>
               <!--- Just let it loop --->
          </cfcatch>
     </cftry>
</cfif> 
</cfloop>

Open in new window

0
 
LVL 1

Author Comment

by:Shawn
ID: 36581903
oops, missign a line. see code below
<cfset strCommonPath = "TestClient\iEnvelopes\" />  
<cfset strFileName = "testimage.jpg" />

<cfset strFilePath = "#expandPath('../../../')#imail_scans" />
<cfset DirectoryTree = Left(strFilePath, 2)>


<cfset strBareFilePath = "#replacenocase(strFilePath, DirectoryTree, "", 'all')#" />
<cfset strFullHostPath = strBareFilePath & replacenocase(strCommonPath, "/", "\", 'all') />
  
<!--- this creates folders if they do not exist on the web host site --->
<cfloop list="#strCommonPath#" index="Directory" delimiters="\">
     <cfset DirectoryTree = ListAppend(strFilePath,Directory,"\")>
 
     <cfif DirectoryExists(DirectoryTree)>
     <cfelse> 
     <cftry>
               <cfdirectory action="Create" directory="#DirectoryTree#"> 
          <cfcatch>
               <!--- Just let it loop --->
          </cfcatch>
     </cftry>
</cfif> 
</cfloop>

Open in new window

0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 1

Author Comment

by:Shawn
ID: 36582355
got it to work with code below.
<cfset strCommonPath = "\" & "TestClient\iEnvelopes\" />  
<cfset strFileName = "testimage.jpg" />

<cfset strFilePath = "#expandPath('../../../')#imail_scans" />
<cfset DirectoryTree = strFilePath>


<cfset strBareFilePath = "#replacenocase(strFilePath, DirectoryTree, "", 'all')#" />
<cfset strFullHostPath = strBareFilePath & replacenocase(strCommonPath, "/", "\", 'all') />
  
<!--- this creates folders if they do not exist on the web host site --->
<cfloop list="#strCommonPath#" index="Directory" delimiters="\">
	 <cfset DirectoryTree = ListAppend(DirectoryTree,Directory,"\")>

     <cfif DirectoryExists(DirectoryTree)> 
     <cfelse> 
     <cftry>
               <cfdirectory action="Create" directory="#DirectoryTree#">
          <cfcatch>
               <!--- Just let it loop --->
          </cfcatch>
     </cftry>
</cfif> 
</cfloop>

Open in new window

0
 
LVL 39

Expert Comment

by:gdemaria
ID: 36582792
Your goal is just to create a directory if it doesn't exist?  given that the creation may involve multiple levels..

 did you ever try this?  I wonder if the command will create multiplevels at once?

<cfset pathToCreate = "testClient/iEnvelopes">
 
<cfset DirectoryTree = expandPath("/") & pathToCreate>
 <cfif NOT DirectoryExists(DirectoryTree)>
      <cfdirectory action="Create" directory="#DirectoryTree#">
 </cfif>
     

0
 
LVL 39

Accepted Solution

by:
gdemaria earned 500 total points
ID: 36582798
If not, here's another version of the code you provided.  I'm having trouble following all the variables, but I think this is all you need... just loop through the relative path, adding the root directory, and create each one...


<cfset pathToCreate = "testClient/iEnvelopes">
<cfset rootDirectory = expandPath("/")>
 
<cfloop index="Directory"  list="#pathToCreate#"  delimiters="\/">
       <cfset DirectoryTree = ListAppend(rootDirectory,Directory,"\")>
     <cfif NOT DirectoryExists(DirectoryTree)>
        <cftry>
        <cfdirectory action="Create" directory="#DirectoryTree#">
         <cfcatch>
              <!--- Just let it loop --->
         </cfcatch>
         </cftry>
     </cfif>
</cfloop>

0
 
LVL 1

Author Comment

by:Shawn
ID: 36582841
>>I wonder if the command will create multiplevels at once?

I tried and it didn't work. found the loop in another ee solution.

just checking your other suggestion. It looks cleaner in any case
0
 
LVL 1

Author Closing Comment

by:Shawn
ID: 36583195
thx again gdemaria.

if you have seen the bug on Q_27322793 before feel free to jump in. agx and I are scratching our heads.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question