FAQ
I have a script in cgi-bin which gathers information from the user
and replaces placeholders in a pre-written html page with the data
collected via a different html interface. Since the script needs to
run from various servers I don't want to use absolute URIs for the
images, css file etc. and I can't work out how to get relative
pathnames to work. I'd be grateful for the solution to this problem,
which I imagine will appear very obvious once I know the answer.

JD

Search Discussions

  • Dermot at Jun 1, 2011 at 3:28 pm

    On 1 June 2011 16:20, John Delacour wrote:
    I have a script in cgi-bin which gathers information from the user and
    replaces placeholders in a pre-written html page with the data collected via
    a different html interface.  Since the script needs to run from various
    servers I don't want to use absolute URIs for the images, css file etc. and
    I can't work out how to get relative pathnames to work.  I'd be grateful for
    the solution to this problem, which I imagine will appear very obvious once
    I know the answer.
    I'd imagine URI's rel method would work well for you in this situation.

    http://search.cpan.org/dist/URI/URI.pm

    HTH,
    Dp.
  • Brandon McCaig at Jun 3, 2011 at 4:11 pm

    On Wed, Jun 1, 2011 at 11:20 AM, John Delacour wrote:
    I have a script in cgi-bin which gathers information from the user and
    replaces placeholders in a pre-written html page with the data collected via
    a different html interface.  Since the script needs to run from various
    servers I don't want to use absolute URIs for the images, css file etc. and
    I can't work out how to get relative pathnames to work.  I'd be grateful for
    the solution to this problem, which I imagine will appear very obvious once
    I know the answer.
    It would probably help if you could show us a simple example of what
    you're trying and what is wrong with it. :) I'm not sure I entirely
    understand what you're doing. If you're just returning <link
    href="blah" /> and <img src="blah" /> tags to the user agent then
    relative paths should work fine, as long as the path in the tags is
    relative to the current Web page.

    For example, if the current Web page is http://foo/bar/baz.html and it
    references css/main.css and images/logo.png then those files should
    exist as http://foo/bar/css/main.css and
    http://foo/bar/images/logo.png on the server. :)

    It doesn't sound like a Perl problem, but an HTML/server problem. :)
    Please elaborate. :)


    --
    Brandon McCaig <http://www.bamccaig.com/> <bamccaig@gmail.com>
    V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl.
    Castopulence Software <http://www.castopulence.org/> <bamccaig@castopulence.org>
  • John Delacour at Jun 3, 2011 at 5:14 pm
    At 12:11 -0400 03/06/2011, Brandon McCaig wrote:

    It would probably help if you could show us a simple example of what
    you're trying and what is wrong with it. :)...

    For example, if the current Web page is http://foo/bar/baz.html
    I made it clear that I am serving the page dynamically from cgi-bin.
    Here is an example:

    <http://bd8.com/cgi-bin/test.pl>

    The image resides in the images/ directory within cgi-bin/.

    Here is the script. The image does not appear.



    #!/usr/local/bin/perl
    use strict;
    use CGI qw~:standard~;
    my $full_url= url(-full=>1);
    print "Content-type: text/html;charset=utf-8\n\n";
    while (<DATA>){
    s/<!--full_url-->/$full_url/;
    print;
    }
    __DATA__
    <html><body><div>
    <p>
    $full_url: <!--full_url-->
    </p>
    <p>
    Image from cgi-bin/images/:
    <img alt="&ldquo;test image&rdquo;" src="images/test.jpg" />
    </p>
    </div></body></html>
  • Brandon McCaig at Jun 5, 2011 at 2:33 am

    On Fri, Jun 3, 2011 at 1:14 PM, John Delacour wrote:
    I made it clear that I am serving the page dynamically from cgi-bin. Here is
    an example:
    That part is irrelevant though because the image file is loaded by the
    user agent AKA Web browser.
    And http://bd8.com/cgi-bin/images/test.jpg fails to download. Instead
    I get an internal server error (HTTP 500). That is your problem. It
    isn't Perl related. Maybe the server refuses to serve the image from
    within the cgi-bin directory for security reasons? Perhaps you should
    move the images into a separate document root and give an absolute
    path e.g., http://bd8.com/images/test.jpg.


    --
    Brandon McCaig <http://www.bamccaig.com/> <bamccaig@gmail.com>
    V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl.
    Castopulence Software <http://www.castopulence.org/> <bamccaig@castopulence.org>
  • John Delacour at Jun 5, 2011 at 8:01 pm
    At 22:33 -0400 04/06/2011, Brandon McCaig wrote:

    On Fri, Jun 3, 2011 at 1:14 PM, John Delacour wrote:
    I made it clear that I am serving the page dynamically from cgi-bin. Here is
    an example:
    That part is irrelevant though because the image file is loaded by the
    user agent AKA Web browser.
    On the contrary, it seems it is not irrelevant at all.
    And http://bd8.com/cgi-bin/images/test.jpg fails to download. Instead
    I get an internal server error (HTTP 500). That is your problem.
    And likely to be the problem of most people attempting the same thing.
    Maybe the server refuses to serve the image from
    within the cgi-bin directory for security reasons?
    Perhaps you should move the images into a separate document root
    and give an absolute path e.g., http://bd8.com/images/test.jpg.
    Well, since the whole matter of the request was the use of relative
    paths, for reasons I've already explained, I am not likely to find
    that recommendation very useful. Indeed I can move the file to [doc
    root]/images/ and link to it as ../images/test.jpg, which I have
    done, but the answer to my question, in case anyone else is
    interested, seems to be that httpd.conf needs to be specially
    configured to regard files in cgi-bin to be regarded as
    non-executables, and since I do not have access to httpd.conf on
    remote servers I cannot serve images from anywhere within cgi-bin.

    JD

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedJun 1, '11 at 3:20p
activeJun 5, '11 at 8:01p
posts6
users3
websiteperl.org

People

Translate

site design / logo © 2022 Grokbase