calling cgi changes default directory

When I call cgi from my html, which takes this same html and outputs it to screen, I can't see images.
Is there any other way to fix the problem than write exact paths
before each image?
I think calling cgi changes default directory to cgi-bin, can I somehow stop that?
kakoAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
maxkirConnect With a Mentor Commented:
Try this code to replace path to images:

$str_from_html_file = <FH_HTML>;
$str_from_html_file =~ s#SRC\s*=\s*"*([^"\s]+)"*#SRC="../$1"#gi ;

print $str_from_html_file;

Is it suitable answer to your problem ?
0
 
maxkirCommented:
Do you use SSI to call CGI ?
Why do you need this scheme ?

Indeed, the current working directory shouldn't affect images et all - but the current path for browser should.

If you have you HTML file as
/dir/file.html
images in:
/images/
and cgi-script:
/cgi-bin/script.cgi

then u can use path to images as
SRC="../images/file.gif"
and this should work for HTML and for CGI.
0
 
kakoAuthor Commented:
I cant use path SRC="../images/file.gif"

cause: I have files in the directories:

/file.html

/image.gif

/cgi-bin/script.cgi




0
 
maxkirCommented:
Is it difficult for you to move file.html to subdirectory ?
This whould solve the problem the simpliest way. Otherwise you'll have to do magic things - replace IMG SRC=a.gif with
IMG SRC="../a.gif"
0
 
Brain2000Commented:
Whenever I run a .CGI program, I always make sure I have changed to the proper directory.  I always write my .CGIs in C.  However, this should be translatable into whatever language you are using.  It works by pulling the command line (i.e. c:\inetpub\wwwroot\test.cgi) and then cutting it off at the last backslash (i.e. c:\inetpub\wwwroot\), then switching to that directory.

void main(int argc,char *argv[])
{
  char *ptr;
  char temp[100];

  //pull the correct directory from argv[0]
  if(argc) {
    strcpy(temp,argv[0]);
    if(ptr=strrchr(temp,'\\')) {
      *ptr=0;
      chdir(temp);
    }
  }
  ...
  ...
}
0
All Courses

From novice to tech pro — start learning today.