Skip to main content
Participating Frequently
October 23, 2008
Question

mystery ExpandPath(".")

  • October 23, 2008
  • 2 replies
  • 470 views
1) I'm trying to save file into the folder - absolute path: c:\coldfusion8\wwwroot\mysite\Images_tools\images. After that I'm trying to set image variable.

2) Action file test.cfm includes only code below and situates in the Images_tools folder.

Code:

<cfform enctype="multipart/form-data">
<cfinput type="file" name="Artfoto">
<cfinput type="submit" name="vov">
</cfform>
<cfset thisDir = ExpandPath(".")>
<cfif structKeyExists(form,"Artfoto") and len(trim(form.Artfoto))>
<cffile action="upload" fileField="Artfoto" destination="#thisDir#" result="fileUpload" nameconflict="makeunique">
<cfif fileUpload.fileWasSaved>
<cfif IsImageFile("#fileUpload.serverfile#")>
<cfimage action="read" source="#fileUpload.serverfile#" name="test">

</cfif>
</cfif>
</cfif>
<!--- result after submit ---->
<cfdump var="#fileUpload.serverfile#">
<cfdump var="#test#">

So, with ExpandPath(".") all work perfect, but file uploads to Images_tools directory NOT to Images, like I need.
If you replace <cfset thisDir = ExpandPath(".")> by
<cfset thisDir = ExpandPath ("images")> or another equivalent ( /images, \images, ..\images, c:\coldfusion8\wwwroot\mysite\images) , you would see in <cfdump> that variable #fileUpload.serverfile# exists and #test# gives us a error.
I don't understand that!!! However with ExpandPath(".") it works perfect, WHY???!!!
How to write a correct path in ExpandPath brackets?

    This topic has been closed for replies.

    2 replies

    Inspiring
    October 24, 2008
    your #test# throws an error because it is trying to get an image from
    the same folder as the calling page, not from /images subfolder.

    change your <cfimage> tag to this:
    <cfimage action="read" source="images/#fileUpload.serverfile#"
    name="test">

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/
    vovasvvAuthor
    Participating Frequently
    October 24, 2008
    To Azadi
    The problem has been solved.
    Grate THANKS!!!!!!!
    Inspiring
    October 24, 2008
    >> <cfset thisDir = ExpandPath("images")>

    that should work, if you are in

    x/y/z/

    and need to get to

    x/y/z/images/


    You might also try

    <cfset thisDir = expandPath('../z/images')>
    which would send you up one, then back down and then into the
    subfolder... but the first one should work, based on what you posted.


    Michael Evangelista, Evangelista Design
    Web : www.mredesign.com Blog : www.miuaiga.com
    Developer Newsgroups: news://forums.mredesign.com