Hi, Patrik.

You should probably be using CGI.pm.  It will vastly simplify what you are
doing.  Then, you can read any of a dozen sites on doing file uploads using
CGI; see search.cpan.org for the details of using CGI.pm.

Sean


On Jan 12, 2008 5:54 PM, Patrik Hasibuan <[EMAIL PROTECTED]>
wrote:

> Dear my friends...
>
> I am still new in perl.
>
> I am writing perl-cgi application for uploading a file. I did "chmod
> 777 ../../artikel". But I get weird displayed message:
> "
> ueri: ------------4CyrMz2ZeGIClwYfFsVdcv Co........
> î 6êÎ]Ë kšfþx·¾ ðfS4M3>º {½‡<Óöù³(R)�¯3çýGèBù= „¬È›øRƒ.....
> &ƒ ÿƒ&m‡îø'-n nÊÐJ(pÇ 9çqîÎ.........
> Ê ¨‚¡ÀÜ EÖ� z!ª˜Y6�¬úÒ„â0J¼"ñË.......
> [end so on. very longg.............]
> ".
>
> And no file copied/uploaded in '../../artikel'. But inserting the record
> onto
> the mysql run properly.
>
> Please tell me why.....
>
> Here I have done:
> deartikel.cgi-->cgideartikel.cgi-->cgiuploadfile.cgi ('-->' means
> 'calls').
> ===
> deartikel.cgi:
> ---
> #!/usr/bin/perl -w
> #use strict;
> use CGI qw(:standard);
> use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
>
> print "Content-type: text/html\n\n";
> print "<html>";
> print "<head>";
> print "</head>";
> print "<body><font style=\"Arial,Arial Black,Helvetica\" size=1>";
> print " <form method=\"post\" action=\"cgideartikel.cgi\"> ";
> print "Title of file <input type=\"text\" name=\"judul\" size=60
> autocomplete=\"ON\"> ";
> print "<input type=\"submit\" value=\"Submit to column 'Articles'.\">
>        <input type=\"reset\" value=\"Input lagi?\">
> print " </form> ";
> print "</body>";
> print "</html>";
> ===
> cgideartikel.cgi:
> ---
> #!/usr/bin/perl -w
> use CGI qw(:standard);
> use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
> use DBI;
>
> print "Content-type: text/html\n\n";
> print "<html>";
> print "<head>";
> print "<title>";
> print "Online Science Org - Data entry kolom karir.";
> print "</title>";
> print "</head>";
> print "<body><font style=\"Arial,Arial Black,Helvetica\" size=1>";
> $pjg=$ENV{"CONTENT_LENGTH"};
> read(STDIN, $kueri, $pjg);
> #print "kueri: $kueri<br>";
> @arr_prm=split("&",$kueri);
> foreach $myprm(@arr_prm){
>  ($namavar,$nilaivar)=split("=",$myprm);
>  $assprm{$namavar}=$nilaivar;
> }
> $i=0;
> foreach my $nv(keys %assprm){
> print "$nv <br>";
> print "$assprm{$nv} <br>";
> print "i = $i <br>";
> $i++;
> }
>
> $judul=$assprm{'judul'};
> print " <form method=\"post\" action=\"cgiuploadartikel.cgi\"
> enctype=\"multipart/form-data\"> ";
> print "Judul<input type=\"text\" name=\"judul\" size=60
> autocomplete=\"ON\"
> value=\"$judul\" readonly> ";
> print "File untuk di-upload";
> print " <input type=\"file\" name=\"url\" size=60 autocomplete=\"ON\"> ";
> print "<input type=\"submit\" value=\"Submit to column 'Artikel'.\">
>        <input type=\"reset\" value=\"Input lagi?\">";
> print " </form> ";
> print "</body>";
> print "</html>";
> &simpan(judul);
>
> sub simpan{
> my $myjudul=shift;
> my $box="localhost";
> my $basisdata="mydb";
> my $db_user_name='root';
> my $db_password='mypw';
> my $dsn="DBI:mysql:$basisdata:$box";
>
> my $dbh = DBI->connect($dsn, $db_user_name, $db_password);
> my $sqlstr=qq{
>    insert into
>        artikel (
>                judul,
>                )
>        values(
>                '$myjudul'
>        )
> };
> my $sth = $dbh->prepare($sqlstr);
> my $status=$sth->execute();
> if($status){
>        $sth->{Commit};
> }else{
>        $sth->{RollBack};
> }
> $dbh->disconnect;
> }
> ---
> cgiuploadfile.cgi:
> ---
> #!/usr/bin/perl -w
> use CGI qw(:standard);
> use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
> print "Content-type: text/html\n\n";
> print "<html>";
> print "<head>";
> print "<title>";
> print "Online Science Org - Data entry kolom karir.";
> print "</title>";
> print "</head>";
> print "<body>";
>
> $pjg=$ENV{"CONTENT_LENGTH"};
> read(STDIN, $kueri, $pjg);
> print "kueri: $kueri<br>";
> exit;
> @arr_prm=split("&",$kueri);
> foreach $myprm(@arr_prm){
>  ($namavar,$nilaivar)=split("=",$myprm);
>  $assprm{$namavar}=$nilaivar;
> }
> $i=0;
> foreach my $nv(keys %assprm){
>  print "$nv <br>";
>  print "$assprm{$nv} <br>";
>  print "i = $i <br>";
>  $i++;
> }
>
> $judul=$assprm{'judul'};
> $url=$assprm{'url'};
> print " <form method=\"post\" action=\"cgiuploadartikel.cgi\"
> enctype=\"multipart/form-data\"> ";
> print " <input type=\"text\" name=\"judul\" size=60 autocomplete=\"ON\"
> value=\"$judul\" readonly> ";
> print "File untuk di-upload";
> print " <input type=\"file\" name=\"url\" size=60 autocomplete=\"ON\"
> readonly> ";
> print "<input type=\"submit\" value=\"Submit to column 'Artikel'.\"
> disabled>
>        <input type=\"reset\" value=\"Input lagi?\" disabled>";
> print " </form> ";
> print "</td></tr>";
>
> my $output_file = "../../artikel/$url";
> my ($bytesread, $buffer);
> my $numbytes = 2000;
> open (OUTFILE, ">", "$output_file")
>        or die "Couldn't open $output_file for writing: $!";
> while ($bytesread = read($url, $buffer, $numbytes)) {
>        print OUTFILE $buffer;
> }
> close OUTFILE;
>
> print "</table>";
> print "</font></body>";
> print "</html>";
> --
> Patrik Hasibuan
> Junior Programmer
> http://www.penguin-teknologi.com
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> http://learn.perl.org/
>
>
>

Reply via email to