Ho trovato alcuni post correlati qui ma, niente di giusto in .. Ho bisogno di servire un'immagine (humm) "correttamente" e usare il minor numero possibile di risorse. Stavo lavorando su un sotto (sotto) ma, non è troppo adatto alle risorse solo per il fatto che utilizzo CGI. Questa è solo la mia ipotesi però. Sono un principiante di Perl ma, mi piace meglio di PHP.Come posso fornire un'immagine con Perl con un po 'di sicurezza e meno risorse?
La query sarebbe generato da "somescript.pl?img=image.png"
#!/usr/bin/perl -Tw
use strict;
use warnings;
use CGI;
#I should drop warnings after all is said and done. Also name my vars generically. Right?
#I dont know if this query method will work or is even the best method.
$query = new CGI;
my @img = $query->param;
if ($_ eq "img") { my $file = $query->param($_); }
if ($_ ne "img") { ## I will send to an error sub that serves up a error image
}
# Prob a one liner to take care of the above. Not within my ability though.
# Still figuring all this out here.. Very verbose sorry...
# I will strip everything but lowercase alpha and the "."
# with s =~ /[something like A-Z] I will look it up //g;
# Still.. prob all above will fit in a one liner by a PERL guru!
# Below is related to -Taint, I was told this is important to use the -T.
$ENV{PATH} = "bin:/usr/bin";
delete($ENV{qw(IFS CDPATH BASH_ENV ENV)});
# now I will grab the images extension.
my $ext = ($file =~ m/[^.]+$/)[0];
#I was informed to use the "three" but, I am unsure what that means.
# My attempt based on my reading many posts here.
my $length = (stat($file))[10];
my $image = do {
local $/ = undef;
print "Content-type: image/$ext\n";
print "Content-length: $length \n\n";
binmode STDOUT;
open(FH, "<", $file) || die "Could not find $file: $!";
my $buffer = "";
while (read(FH, $buffer, 10240)) {
print $buffer;
}
close(FH);
};
Come si può vedere, il mio tentativo qui è ovviamente un principiante.
Ho trovato un ottimo consiglio qui in overflow dello stack. Ringrazio tutti passato e presente.
Si prega di inserire il codice in un blocco di codice (aggiungere 4 spazi prima di ogni riga), è completamente illeggibile al momento –
Scusa, pensavo di averlo fatto. –
Grazie Adam! Non so perché il blocco di codice non funzionasse per me. Il mio male è ovvio ... –