sub uploadPhoto{ my $self = shift; my $q = $self->query; my $admin=($self->session->param('membership') =~ /$Intranet::Web::CONFIG{securityldapsuper}/); my $jpegimg=''; my $photo = $q->upload('photo'); my $dn=$q->param('dn'); if($photo && $admin && $dn){ binmode($photo); my $ft = File::Type->new(); # return "type=".$ft->checktype_contents($photo); #used for testing my $image = GD::Image->newFromGif($photo); unless($image){$image = GD::Image->newFromJpegData($photo);#tried this and newFromJpeg with the same result unless($image){return "Not a valid gif or jpeg file.";}} $jpegimg=$image->jpeg(); undef $image; unless($jpegimg){return "Problem uploading image.";} my $ldap=Net::LDAP->new($Intranet::Web::CONFIG{ldaphost}) or die "error connecting to LDAP $Intranet::Web::CONFIG{ldaphost}: $@\n"; my $mesg=$ldap->bind($Intranet::Web::CONFIG{ldapuser}, password=>$Intranet::Web::CONFIG{ldappassword}) or die "error binding: $@\n"; if($jpegimg){ my $mesg1=$ldap->modify($dn,replace=>{jpegPhoto=> $jpegimg,thumbnailPhoto=>$jpegimg, }); $mesg1->code && die $mesg1->error; } $ldap->unbind; } return "Photo uploaded".(length($jpegimg)); } ####