Database Reference
In-Depth Information
# Must have either no parameters (in which case that script was just
# invoked for the first time) or both parameters (in which case the form
# was filled in). If only one was filled in, the user did not fill in the
# form completely.
my $param_count = 0 ;
++ $param_count if defined ( $image_file ) && $image_file ne "" ;
++ $param_count if defined ( $image_name ) && $image_name ne "" ;
if ( $param_count == 0 ) # initial invocation
{
print p ( "No file was uploaded." );
}
elsif ( $param_count == 1 ) # incomplete form
{
print p ( "Please fill in BOTH fields and resubmit the form." );
}
else # a file was uploaded
{
my ( $size , $data );
# If an image file was uploaded, print some information about it,
# then save it in the database.
# Get reference to hash containing information about file
# and display the information in "key=x, value=y" format
my $info_ref = uploadInfo ( $image_file );
print p ( "Information about uploaded file:" );
foreach my $key ( sort ( keys ( % { $info_ref })))
{
print p ( "key="
. escapeHTML ( $key )
. ", value="
. escapeHTML ( $info_ref -> { $key }));
}
$size = ( stat ( $image_file ))[ 7 ]; # get file size from file handle
print p ( "File size: " . $size );
binmode ( $image_file ); # helpful for binary data
if ( sysread ( $image_file , $data , $size ) != $size )
{
print p ( "File contents could not be read." );
}
else
{
print p ( "File contents were read without error." );
# Get MIME type, use generic default if not present
my $mime_type = $info_ref -> { 'Content-Type' };
$mime_type = "application/octet-stream" unless defined ( $mime_type );
Search WWH ::




Custom Search