Hello, I have a simple perl script that connects to an LDAP server, searches for a user ID, then extracts the photo of that user and prints it to a file. The only problem, is that the printed file is not recognized as a photo. I believe that the file is stored in LDAP in either JPG format or HEX format. Either way, I need to print the file as a JPG. Any suggestions? Here is the code:

#open a connection to LDAP my $ldap = Net::LDAP->new ( "$idvServer" ) or die "$@"; my $result = $ldap->bind ( "$idvAdmin", password => "$idvPW", version +=> 3 ) or die($result->error()); # open the input file open WFIDS, "<$inputFile" or die("Could not open input file."); open LOGFILE, ">>$logFile" or die("Could not open log file."); foreach $empID (<WFIDS>) { chomp($empID); # remove the newline from $line. my $filter = "(workforceID=$empID)"; $mesg = $ldap->search (base => $userBase, filter => "$filter", sco +pe => "$scope", attrs => $userAttributes) ; $totalFound=$mesg->count; # determine the number of entries found, + should only be one my @entries = $mesg->entries; if ($totalFound eq 1) { my $photo = $entries[0]->get_value('photo'); open OUTFILE, ">${outputFile}${empID}.jpg" or die("Could not c +reate the empID file."); print OUTFILE "$photo"; close OUTFILE; print LOGFILE "Found 1 ID for $empID\n"; } else { print LOGFILE "Found more than 1 ID or found 0 IDs for $empID\ +n"; } } close(WFIDS); close LOGFILE; $ldap->unbind;


In reply to Saving Photos stored in LDAP by fritz1968

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.