At 05:56 PM 08/21/02 +0800, Connie Chan wrote: >No... I believe. I've digging on this topic for very very long >time on my Win32, Sambar and Apache server. > >I can't print any image out without \r\n\r\n, where \n\n is for >text file only. Why? I don't know =) Guess, because \r\n is for >*binmoded data*.
Might be helpful to spend some time with tcpdump or ethereal. Or google. \n\n is a signal to the web server that you are done sending headers -- the web server will then rewrite the headers for you. Sending \r\n\r\n makes no difference, as what gets sent to the client is a function of the web server's header output code. Take a look with a packet sniffer. >And without binmode STDOUT and IMAGE both. the read / print >process will terminated after 1024k. Why? I don't know either. because without binmode (on Windows) the image will get modified -- \r\n -> \n reading in and \n -> \r\n writing out. >> print "Content-type: image/jpeg\n\n"; >> binmode IMAGE; >> while(<IMAGE>){ >> print; >> } while what? How about something like: #!/usr/local/bin/perl -w use strict; open IMAGE, 'test.jpg' or die "Failed to open image $!"; my $buf_chunk_size = 1024 * 16; my $buffer; binmode IMAGE; binmode STDOUT; print "Content-Type: image/jpeg\n\n"; print $buffer while read IMAGE, $buffer, $buf_chunk_size; >----- Original Message ----- >From: "david" <[EMAIL PROTECTED]> >To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> >Sent: Wednesday, August 21, 2002 6:48 AM >Subject: Re: Help!! Retrieving Image File > > >> not sure if you already have the answer to this one but you: >> >> binmode IMAGE; >> print "Content-type: image/jpeg\n\n"; >> while(<IMAGE>){ >> print; >> } >> >> should probably be: >> >> print "Content-type: image/jpeg\n\n"; >> binmode IMAGE; >> while(<IMAGE>){ >> print; >> } >> >> you need to print the text header first and than print the >> binary image. try it and see if it works or not. >> >> alos, use "\n\n" is better than "\r\n\r\n" because "\n\n" is more >> portable. you also don't need to binmode STDOUT >> >> david >> >> Perl wrote: >> >> > Hello All, >> > >> > I created a simple http upload file routine that uploads file into my >> > accounts sub folder uploads, "/home/myaccount/uploads". This is >> > already running. >> > >> > Now what I wanted to do is retrieve the uploaded file from the >> > browser, and display the content in the browser if it is an image or >> > a text/html file, if not then download it. I made a simple code and >> > its not working for the image file, I hope someone here in the list can >> > help me. >> > >> > Here are the sample code that I've tried so far and it didn't work. >> > Kindly please tell me what I missed.... >> > >> > >> > Code 1: It didnt work... >> > >> > #!/usr/bin/perl >> > >> > use CGI; >> > $query = new CGI; >> > my $filepath='/home/myaccount/uploads/laptop.jpg'; >> > >> > print $query->header('image/jpeg'); >> > print $filepath; >> > >> > >> > Code 2: This code is running ok with text/html files, but not with the >> > images, I hope someone here can help me. >> > >> > >> > #!/usr/bin/perl >> > >> > my $filepath="/home/rce/uploads/drugs.jpg"; >> > >> > open(IMAGE, $filepath); >> > binmode IMAGE; >> > >> > print "Content-type: image/jpeg\n\n"; >> > while(<IMAGE>){ >> > print; >> > } >> > >> > >> > >> > Thanks in advance >> > >> > Archie >> >> >> -- >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> For additional commands, e-mail: [EMAIL PROTECTED] >> >> > > -- Bill Moseley mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]