mimsc 0 Junior Poster in Training

Hello all. Im a Java developer, but have been given the extra title of Perl developer also. So im new to the code structure. Basically Im trying to pull the width and height from a url example below and display in an error msg just to test:

http://...readimage?1234a&height=10&width=10

use strict;
use warnings;
use CGI::Carp qw(fatalsToBrowser);
use CGI::Fast qw(:standard);
use LWP::UserAgent;
use Sys::Hostname;
use File::stat;
use Date::Format;
use Image::Magick;

### Image Path Hash Module
require "/web/images/perl/hash.pm";

my $image_path = '/web/images';
my $image_path_old = '/web/imgsrv';
my $ecode;
my %GET = ();
my $width;
my $height;

while ( my $cgi = new CGI::Fast ) {
   %GET = $cgi->Vars();

   if ( $GET{'keywords'} || $GET{'width'} ||  $GET{'height'} ) { # Data was included, attempt to process (stops bare readimage calls)
my $external_id;
$width = $GET{'width'};
$height = $GET{'height'};
$external_id = $GET{'keywords'};

      if ( $ENV{'PATH_INFO'} ) { # Called via / (PATH_INFO will contain either a URL or an external ID)
         if ( $ENV{'PATH_INFO'} =~ /\/http:\// ) { # This is a separate logic branch for image URLs (Note the single slash in the RE--double slashes are int$
            if ( $ENV{'PATH_INFO'} !~ /\.exe$/ ) { # This will prevent URLs with .exe extensions from being processed
               if ( $ecode = run_url('http://' . substr($ENV{'PATH_INFO'}, 7), $cgi) ) { # substr() fixes the double/single slash problem caused by the HTTP$
                  error($cgi, "URL processing failed, error number $ecode");
               }
               next();
            } else {
               error($cgi, 'Invalid URL (.exe detected)');
               next();
            }
         }
         error($cgi, 'Valid External test1 ID or URL Required') if $ENV{'PATH_INFO'} =~ /\/\D/;
         error($cgi, 'Valid External test2 ID or URL Required') if length $ENV{'PATH_INFO'} > 21; # Should only accept URLs or a number of <=20
digits
         $external_id = substr($ENV{'PATH_INFO'},1);
      } else { # Called via ? (%GET will contain all passed cgi variables)
         if ( $GET{'keywords'} =~ /http:\/\// ) { # This is a separate logic branch for image URLs
            if ( $ecode = run_url($GET{'keywords'}, $cgi) ) {
               error($cgi, "URL processing failed, error number $ecode");
            }
            next();
         }
         error($cgi, 'Valid External test3 ID', $external_id, $height, $width) if $GET{'keywords'} =~ /\D/;



//<-- this display the error msg//
sub error {
   my ($cgi, $emsg, $var, $var2, $var3) = @_;

   print $cgi->header(),  $cgi->start_html('Error'), $cgi->h1("Error: $emsg $var $var2 $var3"), $cgi->end_html;
   next();
}

my error message outputs :
Error: Valid External test3 ID 1234a

Looks like it dis-regards the width and height parameters. Any ideas why?

Thanx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.