Where to install stock of images for a script

B

BlinKol

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 ?
 
M

Matt Garrish

BlinKol said:
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
 
X

xhoster

BlinKol said:
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
 
B

BlinKol

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).
 
B

BlinKol

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.
 
G

Gunnar Hjalmarsson

BlinKol said:
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__
 
B

BlinKol

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 !
 
B

BlinKol

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 ?
 
T

Tad McClellan

[ 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.
 
B

BlinKol

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 :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top