Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Where to install stock of images for a script

1 view
Skip to first unread message

BlinKol

unread,
Jan 11, 2006, 2:53:49 PM1/11/06
to
Considering a script that needs a fixed stock of images during its
process and knowing that this stock shouldn't be accessible out of the
script, where would you install these images ?

In my mind, the best would be to upload them in the same directory as
the Perl script himself, but it doesn't work : server-log says that the
image file is not exacutable and that it don't know how to handle it.

Here is a short test script to show what I want to say :

-- BEGIN OF /cgi-bin/test/test.pl SCRIPT --
#!c:/perl/bin/Perl.exe

print "Content-type: text/html\n\n";
print "<HTML><BODY>";
print "<img src='/cgi-bin/test/test.gif' border=0>";
print "</BODY></HTML>";
exit 0;
-- END OF SCRIPT --

The image doesn't appear in browser and server's error log says this :

-- FROM ERROR LOG --
[Wed Jan 11 20:40:17 2006] [error] [client 127.0.0.1]
C:/websites/vhosts/dev/cgi-bin/test/test.jpg is not executable; ensure
interpreted scripts have "#!" first line, referer: http://dev-desk/cgi-
bin/test/test.pl

[Wed Jan 11 20:40:17 2006] [error] [client 127.0.0.1] (9)Bad file
descriptor: don't know how to spawn child process:
C:/websites/vhosts/dev/cgi-bin/test/test.jpg, referer: http://dev-
desk/cgi-bin/test/test.pl
-- END OF ERROR --

Also, this test has been ran in Apache/ActivePerl under Windows, whitout
permission concern.

Do you have an idea about this error ? How would you do ?

Matt Garrish

unread,
Jan 11, 2006, 3:03:45 PM1/11/06
to

"BlinKol" <.@.> wrote in message
news:MPG.1e2f80b53...@news.tiscali.fr...

> Considering a script that needs a fixed stock of images during its
> process and knowing that this stock shouldn't be accessible out of the
> script, where would you install these images ?
>

Considering it's rude to post the same question again, I would suggest
stopping.

Matt


xho...@gmail.com

unread,
Jan 11, 2006, 3:19:05 PM1/11/06
to
BlinKol <.@.> wrote:
> Considering a script that needs a fixed stock of images during its
> process and knowing that this stock shouldn't be accessible out of the
> script, where would you install these images ?

I wouldn't install them at all. Since the script you show doesn't access
the images, and they shouldn't be accessible out of the script, then they
are never accessed and thus are not needed.

> In my mind, the best would be to upload them in the same directory as
> the Perl script himself, but it doesn't work : server-log says that the
> image file is not exacutable and that it don't know how to handle it.

Have the Perl script open the image, and send it out to the browser.

>
> Here is a short test script to show what I want to say :
>
> -- BEGIN OF /cgi-bin/test/test.pl SCRIPT --
> #!c:/perl/bin/Perl.exe
>
> print "Content-type: text/html\n\n";
> print "<HTML><BODY>";
> print "<img src='/cgi-bin/test/test.gif' border=0>";
> print "</BODY></HTML>";
> exit 0;
> -- END OF SCRIPT --

Here your Perl script is telling the user's browser to go get the image.
But you just said that only the Perl script (and hence not the user's
broswer) should be able to access the image. You can't have your cake
and eat it too.

Assuming you actually do want the images to be accessible to the user's
browser, then you need to move the images to a directory where your
web-server is willing to serve them from, or configure your web-server so
that it will serve images out of the cgi-bin directory rather than trying
to execute them as code (for example, by detecting the "jpg" ending),
neither of which have anything to do with Perl; or you need to make your
perl script serve up the images itself.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB

BlinKol

unread,
Jan 11, 2006, 3:54:32 PM1/11/06
to
In article <wwdxf.18940$W03.5...@news20.bellglobal.com>,
matthew...@sympatico.ca says...

> Considering it's rude to post the same question again, I would suggest
> stopping.
>
> Matt
>
>
Sorry, but I did canceled the first one and reposted to correct an error
in my first message (about error).

BlinKol

unread,
Jan 11, 2006, 4:11:46 PM1/11/06
to
In article <20060111151905.079$a...@newsreader.com>, xho...@gmail.com
says...

> Here your Perl script is telling the user's browser to go get the image.
> But you just said that only the Perl script (and hence not the user's
> broswer) should be able to access the image. You can't have your cake
> and eat it too.
>
>

Thanks ! So obvious :-( So, how to manage the open to display the image
in an html page ? But, I've reposted the same question in
comp.infosystems.www.authoring.cgi since not perl specific.

Gunnar Hjalmarsson

unread,
Jan 11, 2006, 6:31:46 PM1/11/06
to
BlinKol wrote:

> xho...@gmail.com wrote:
>>Here your Perl script is telling the user's browser to go get the image.
>>But you just said that only the Perl script (and hence not the user's
>>broswer) should be able to access the image. You can't have your cake
>>and eat it too.
>
> Thanks ! So obvious :-( So, how to manage the open to display the image
> in an html page ? But, I've reposted the same question in
> comp.infosystems.www.authoring.cgi since not perl specific.

Well, I for one find it hard to understand that how to do it in Perl
wouldn't be enough Perl related to show here... This is an example:

#!c:/perl/bin/Perl.exe -T
# test.pl
use strict;
use warnings;

my $imagedir = '/path/to/image/directory';
my $imagename = 'myimage.gif';
my $ctype = 'image/gif';

use CGI;
my $cgi = CGI->new;
if ( $cgi->param('img') ) {
imgprint("$imagedir/".$cgi->param('img'), $ctype);
} else {
htmlprint($imagename);
}

sub imgprint {
my ($path, $type) = @_;
print $cgi->header($type);
open my $f, $path or die "Couldn't open $path: $!";
binmode $f;
binmode STDOUT;
print while read $f, $_, 1024;
}

sub htmlprint {
my $imgname = shift;
print $cgi->header, <<HTML;
<html><body>
<img src="test.pl?img=$imgname" />
</body></html>
HTML
}
__END__

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

BlinKol

unread,
Jan 12, 2006, 5:15:03 AM1/12/06
to
In article <42lir3F...@individual.net>, nor...@gunnar.cc says...

> Well, I for one find it hard to understand that how to do it in Perl
> wouldn't be enough Perl related to show here... This is an example:
>

Tanks a lot Gunnar !

BlinKol

unread,
Jan 12, 2006, 5:43:59 AM1/12/06
to
> Well, I for one find it hard to understand that how to do it in Perl
> wouldn't be enough Perl related to show here... This is an example:
>
> #!c:/perl/bin/Perl.exe -T
> # test.pl
> use strict;
> use warnings;
>
> my $imagedir = '/path/to/image/directory';
> my $imagename = 'myimage.gif';
> my $ctype = 'image/gif';
>
> use CGI;
> my $cgi = CGI->new;
>
> ...

Well, here is the code without use of CGI package, in Perl :

#!c:/perl/bin/Perl.exe
use strict;
my $img = "test.jpg"; # same dir as current script
print "Content-Type: image/jpeg\n\n";
open FILE, $img or die "Couldn't open $img : $!";
binmode FILE;
binmode STDOUT;
print while read FILE, $_, 1024;
close FILE;

Maybe forgotten something around "Content-Length" (don't know), but,
apparently, it works fine.

Then, from this point I would like to be able to push test.jpg in the
framework of a generated html page. Something like this doesn't work :

#!c:/perl/bin/Perl.exe
use strict;
print "Content-type: text/html\n\n<HTML><BODY>";
print "<p>This is an image from cgi-bin space :</p><CENTER>";

my $img = "test.jpg"; # same dir as current script
print "Content-Type: image/jpeg\n\n";
open FILE, $img or die "Couldn't open $img : $!";
binmode FILE;
binmode STDOUT;
print while read FILE, $_, 1024;
close FILE;

print "</CENTER></BODY></HTML>";
exit 0;

How to do ?

Tad McClellan

unread,
Jan 12, 2006, 7:35:39 AM1/12/06
to
BlinKol <.@.> wrote:
> In article <42lir3F...@individual.net>, nor...@gunnar.cc says...
>> Well, I for one find it hard to understand that how to do it in Perl
>> wouldn't be enough Perl related to show here... This is an example:

[ snip ]

> Then, from this point I would like to be able to push test.jpg in the


Why would you like to do that?

If we know what your objection is, we might be able to come up
with a workaround for it...


> framework of a generated html page.


I don't know what a "framework of a generated html page" is.


> Something like this doesn't work :
>
> #!c:/perl/bin/Perl.exe
> use strict;
> print "Content-type: text/html\n\n<HTML><BODY>";
> print "<p>This is an image from cgi-bin space :</p><CENTER>";
>
> my $img = "test.jpg"; # same dir as current script
> print "Content-Type: image/jpeg\n\n";
> open FILE, $img or die "Couldn't open $img : $!";
> binmode FILE;
> binmode STDOUT;
> print while read FILE, $_, 1024;
> close FILE;
>
> print "</CENTER></BODY></HTML>";
> exit 0;


It doesn't work because that is not how HTTP and browsers work.

If you have a web page that includes 2 images, the browser will
make *three* HTTP requests, then stitch together the 3 results
for rendering.


> How to do ?


Output an <img> element whose src is a CGI program that returns
the correct response (an image in this case).

That is just what Gunnar's followup showed.

If you can describe what it is about Gunnar's approach that you
don't like, then maybe we can suggest an alternative.


--
Tad McClellan SGML consulting
ta...@augustmail.com Perl programming
Fort Worth, Texas

BlinKol

unread,
Jan 12, 2006, 7:57:27 AM1/12/06
to
In article <slrndscj8r...@magna.augustmail.com>,
ta...@augustmail.com says...

> Output an <img> element whose src is a CGI program that returns
> the correct response (an image in this case).
>
> That is just what Gunnar's followup showed.
>
>
OK, it works now. In fact, I wanted to have entire code in the same
script. Then, I've included the Gunnar code (modified version without
use of CGI) in a sub, then call it through a self call with a parameter
in url like <http://dev-desk/cgi-bin/test/test.pl?load="test.jpg">.

Thanks to you and Gunnar :)

0 new messages