Saturday, June 28, 2014

Getting Images from a PERL Directory

            $file = "<root library name here>/test/images/$file";
            
            #print MYFILE "URL: $file\t";

            my $length = (stat($file)) [10];

            #print MYFILE "Test Point 1\n";
            
            my $fileContent =  "Content-type: image/jpg\n";

            #print MYFILE "Test Point 2\n";
            
            $fileContent = $fileContent . "Content-length: $length \n\n";
            
            #print MYFILE "Test Point 3\n";
            
            #binmode STDOUT;
            
            open (FH,"<$file") or die "Could not open $file: $!";

            #print MYFILE "Test Point 4\n";
            
            my $buffer = "";
            
            #print MYFILE "Test Point 5\n";
            
            while (read(FH, $buffer, 10240))
            {
                
                $fileContent = $fileContent . $buffer;
            
                #print MYFILE "Test Point 6\n";
            
            }
            
            close(FH);

            #print MYFILE "Test Point 7\n";
            

return $fileContent;

No comments:

Post a Comment