Set the directory fails in a CGI

Sannyasin Sivakatirswami katir at hindu.org
Sun Oct 17 01:07:00 EDT 2004


I have a script that runs fine in a button. where I usually develop CGI 
first, locally (see below) the script reads a semaphore file which sets 
a target group of image collections which are to be use to poke generic 
image file names. thus rotating images on the web.

After careful testing I have discovered the "break point"

It is simply this:

I can tell the CGI to

set the directoy to gStem

at the beginning of the script... but any attempt later to set the 
defaultFolder to a different folder will fail.. whether or not it is in 
a function, a handler or in the main script repeat loop itself. it 
keeps defaulting back to the cgi-bin as the default folder and "the 
files" will contain a list of my CGI's.

I've tested the stnOut for all variables at various points in the main 
script and also in the function and directoryWalk handler... and they 
are all being poked as expected... see comments in the script for where 
the problem lies.

=======



global gFileList,gMainFolder, gStem, gImageSet, gSource, 
gCollectionTarget, gDaKin

on startUp
   put empty into gFileList
     put empty into gMainFolder
   put empty into gStem
   put empty into gImageSet
   put empty into gSource
     put empty into gCollectionTarget


   put "../htm/taka/images/taka_04_10_15/" into gStem

## if i do this now:
set the directory to gStem
put the files into buffer
  put "Content-Type: text/html" & cr
   put "Content-Length:" && the length of buffer & cr & cr
    put buffer
##  a list of images in the gStem directory is returned as expected

   # Create a small array of the targets
   put "bg-top,bg-bottom,symbol" into tCollections
   split tCollections by comma

   ## now get the collection pointer, a small semaphore file with a 
single word
   put url ("file:" & gStem &"collection_target.txt")into gImageSet


   ## Now step through the three targets:
   repeat with x = 1 to 3
     put tCollections[x] into gCollectionTarget
     put gStem & gCollectionTarget & ".jpg" into gTargetPath
     put chooseImage(gCollectionTarget,gImageSet) into gSource
     put URL  ("binfile:" & gSource) into URL ("binfile:" & gTargetPath)
## works fine in a button that runs from a stack
## with paths to the local web site on our server
     put empty into gFileList
   end repeat
   put jai

end mouseup

function chooseImage gCollectionTarget,gImageSet
   if gImageSet ="random" then
    directoryWalk (gStem & gCollectionTarget)
   else
     set the defaultFolder to (gStem & gCollectionTarget &"/" & 
gImageSet & "/")
     put the files into gFileList
## if run from my stack: I get a list of images from the collection 
folder as expect
## but if run as a CGI the files will now be
    ##  from the cgi-bin itself and *not* from the folder
## that is being set as the defaultFolder
## this fails whether I turn the function into a handler that pokes a 
global
## or even if I move this whole thing up into the repeat segment itself
## the attempt to set the directory again will fail.
## both in Darwin and on Linux running under Apache
   end if
   put line (random (the number of lines of gFileList)) of gFileList 
into gSource
   return gSource
end chooseImage

on directoryWalk whatFolder
   set the itemDel to "/"
   set the directory to whatFolder
   put the files into temp
   repeat for each line x in temp
     put whatfolder & "/" & x & cr after gFileList
   end repeat
   put the folders into tDirList
   delete line 1 of tDirList
   repeat for each line x in tDirList
     if x = ".."  then next repeat
     directoryWalk (whatFolder & "/" & x)
   end repeat
end directoryWalk



More information about the use-livecode mailing list