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?
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

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 ?
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
images in:
and cgi-script:

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

cause: I have files in the directories:




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"
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) {
    if(ptr=strrchr(temp,'\\')) {
All Courses

From novice to tech pro — start learning today.