Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

coldfusion expandpath use with recordset

Posted on 2010-11-11
13
Medium Priority
?
497 Views
Last Modified: 2012-05-10
I am using code to bulk upload images to a server. I works perfectly, but I need it to work with a 'dynamic' name for the folder with will receive the images. I would like some advice as to whether the approach is feasible - as I say it works for a given receiving directory name, but not for a dynamic directory name.

You will see in the code attached, that I have a recordset which selects one record and I am trying to use that result for the name of the receiving folder. I show in the code the two examples of where this approach is taken.

Advice needed as to whether this approach is correct or am I infringing some basic coldfusion rules. Plese remember that the overall approach does work when I hard wire in a directory name and also that the recordset and the output does work correctly in a simple test page

Thanks for some guideance

james
=========================================
THE RECORDSET

<cfquery name="Recordset1" datasource="abac">
SELECT *
FROM pagedata
WHERE ID = 41 
</cfquery>

====================================================
================================================
useage example 1
<cfset myDir = "#expandpath(".")#\<Cfoutput>#RECORDSET1.himages#</cfoutput>\" />

====================================================
usage example 2

<cfdirectory
action="list"
directory="#ExpandPath( './<cfoutput>#RECORDSET1.himages#</cfoutput>/' )#"
recurse="true"
name="mylist"
/>

Open in new window

0
Comment
Question by:jameskane
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
13 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 34115552
>> <cfset myDir = "#expandpath(".")#\<Cfoutput>#RECORDSET1.himages#</cfoutput>\" />

There is no reason you can't use dynamic directory paths.  Though you do not need any of those cfoutput tags. Nesting also decreases readability IMO.  ie Instead use  

       <cfset myDir =  expandpath(".") &"\"& RECORDSET1.himages />

So when you say it doesn't work, what happens .. an error? The first thing to check is the the resulting values. Do they create a valid path?

         #expandpath(".")#
         #RECORDSET1.himages#
         #myDir#

0
 

Author Comment

by:jameskane
ID: 34119602
Hi Agx, thanks again for helping me out. Below is the path that is being created. I note the space between teleimage and \himagesPeinture.  

D:\Inetpub\coin-des-artistes\teleimage \himagesPeinture

Initially it was  D:\Inetpub\coin-des-artistes\teleimage himagesPeinture, but I changed the value in the database from himagespeinture to \himagespeinture.

However, I am unable to get rid of the space.

I am attaching the relelvent bits of code, maybe you can see a way of getting rid of that space !! That should fix it !!

The program is not crashing, I am just not getting the images into the target folder which is himagespeinture. Again, everything works if I hard wire in the name of the folder, vrs taking the dynamic route.

thanks again, james
RENAMING.CFM page
---------------------------------------------------------------
<cfquery name="Recordset1" datasource="abac">
SELECT *
FROM pagedata
WHERE ID = 41 
</cfquery>

++++++++++++++++++++++++++++++++++++++++

<cfdirectory
action="list"
directory="#expandpath(".")&"\"&RECORDSET1.himages#" 
recurse="true"
name="mylist"
>

+++++++++++++++++++++++++++++++++++++++++++++++

This is for renaming the image files to a standard photo1.jpg, photo2.jpg etc...

<cfset imageNumber = 1>
Your files have be uploaded succesfully

<cfloop query="mylist">
     <cfif mylist.type eq "file">
          <cffile 
          action="move" 
          source="#mylist.directory#\#mylist.name#" 
          destination="#mylist.directory#\photo#imageNumber#.#listlast(mylist.name,'.')#">
          <cfset imageNumber = imageNumber + 1>
     </cfif>
</cfloop>


--------------------------------------------------------
page folderuploader_hdlr
---------------------------------------------------------
<cfquery name="Recordset1" datasource="abac">
SELECT *
FROM pagedata
WHERE ID = 41 
</cfquery>


<cfset myDir=expandpath(".")&"\"&RECORDSET1.himages />

==============================================================
<cfset variables.destination=expandpath(".")&"\"&RECORDSET1.himages />

Open in new window

0
 

Author Comment

by:jameskane
ID: 34120012
Woops, I think the above analysis is not correct. Sorry for that. I used

<cfoutput> #expandpath(".")#
 #TRIM(RECORDSET1.himages)#
         </cfoutput>


in the renaming page to get the path - which showed the space problem. However, if I
use

 <cfoutput> #expandpath(".")# #TRIM(RECORDSET1.himages)#
         </cfoutput>

I do not get the space

Woops...
0
What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 34121164
Verify the paths you're using at each step with DirectoryExists() and FileExists().  That's the only way to tell if the paths are valid.  Make sure to use the exact same paths though.

      ie <cfdirectory directory="#expandpath(".")&"\"&RECORDSET1.himages#" ....>

       <cfoutput>
       #expandpath(".")&"\"&RECORDSET1.himages#
      <cfif DirectoryExists("#expandpath(".")&"\"&RECORDSET1.himages#")>
          exists
       <cfelse>
            does not exist
       </cfoutput>

Also, dump #mylist# to verify it actually contains results.  If it's empty, that would explain why nothing seems to be happening.
0
 

Author Comment

by:jameskane
ID: 34130614
hI  again agx !

Well I have pinned this down now to the following :

<cfset myDir = "#expandpath(".")#\himagesPeinture\" />    THIS WORKS

<cfset myDir = "#expandpath(".")&"\"&RECORDSET1.himages#" /> THIS DOES NOT WORK

I have checked that  recordset1.himages  does give an output "himagesPeinture" - so its not that

?? syntax problem maybe ?

James
0
 
LVL 52

Expert Comment

by:_agx_
ID: 34130931
Almost definitely a syntax problem. If you print out #myDir#  what are the values?

>> <cfset myDir = "#expandpath(".")&"\"&RECORDSET1.himages#" /> THIS DOES NOT WORK

I don't know what results that would produce, but the way I'd write it is:

         <cfset myDir = expandpath("./"& RECORDSET1.himages) />

Get rid of all the extra pound signs and quotes. They just confuse things :)
0
 

Author Comment

by:jameskane
ID: 34130961
Got it Agx !!  

It was the  />  -- at the end of <cfset myDir = "#expandpath(".")&"\"&RECORDSET1.himages#" />... Should have been just > and not />.

Thanks for the tools you pointed to, without those I would have not been able to resolve it !!

James

PS... also thanks for  you past pointer to jquery !!!!  Its really fantastic. I am redoing the complete art school website with it - to maximize potential for the non tech owners to input the content themselves via database. This little problem came from this work !!

0
 

Author Closing Comment

by:jameskane
ID: 34130968
THANKS !!
0
 
LVL 52

Expert Comment

by:_agx_
ID: 34131018
>> It was the  />  -- at the end of

Hm... I don't think so.  It shouldn't make any difference. These 2 produce the same results. Though the 2nd is easier on the eyes ;-)

<cfset RECORDSET1.himages = "someFolder">
<cfset myDir = "#expandpath(".")&"\"&RECORDSET1.himages#" />
<cfoutput>#myDir#</cfoutput><br>

<cfset myDir = expandpath("./"& RECORDSET1.himages) />
<cfoutput>#myDir#</cfoutput>
0
 

Author Comment

by:jameskane
ID: 34131404
you are right !  don't know how that came about !!!

BUT, a bit more experimentation and eventually - this REALLY works

<cfset myDir = "#expandpath(".")#\#recordset1.himages#\" />

James
0
 
LVL 52

Expert Comment

by:_agx_
ID: 34131804
>> <cfset myDir = "#expandpath(".")#\#recordset1.himages#\" />

You realize you're killing me with the extra /'s # signs and quotes ;-)  But I admit not everyone cares for using "&" the way I do :)  

BTW: ExpandPath(".") returns a directory.  So you could simply write it as

<cfset myDir = expandpath("./#RECORDSET1.himages#")  />
0
 

Author Comment

by:jameskane
ID: 34131815
Fantastic !!

Don't die !!!

I need you !!

very many thanks

james
0
 
LVL 52

Expert Comment

by:_agx_
ID: 34131835
ROFL ;-)  
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

661 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