Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hi monks!

I have written a web app that I want to be able to upload pics into ldap. Gif's work just fine, but jpeg's aren't. Apache log says: "gd-jpeg: JPEG library reports unrecoverable error: Not a JPEG file: starts with 0x47 0x3a". I used File::Type to test the data type and for both gif's & jpeg's, it returns "application/octet-stream". I'm assuming the gif library can handle "application/octet-stream", but the jpeg lib can't??? Is there a way I can get this to work for both jpegs & gif's or am I going with the wrong approach?

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($ph +oto);#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{ldaphos +t}) 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 bindin +g: $@\n"; if($jpegimg){ my $mesg1=$ldap->modify($dn,replace=>{jpegPhot +o=> $jpegimg,thumbnailPhoto=>$jpegimg, }); $mesg1->code && die $mesg1->error; } $ldap->unbind; } return "Photo uploaded".(length($jpegimg)); }
and my html:
<form name='photoForm' action='[% userbase %]/ldap.pl' enctype="multip +art/form-data" method='post' id='photoForm'> <input type="hidden" name="rm" value="getDetailUser"> <input type="hidden" name="upload" value="0"> <input type="hidden" name="dn" value="[% user.dn %]"> <input type="file" name='photo'> <input type="button" value='Upl +oad' onclick='this.form.upload.value=1;this.form.submit();'> </form>

In reply to Uploading pics to ldap through webapp by ksublondie

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-23 18:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found