perl for uploading file shows weird characters.

perl for uploading file shows weird characters.

am 12.01.2008 23:55:50 von Patrik Hasibuan

Dear my friends...

I am still new in perl.

I am writing perl-cgi application for uploading a file. I did "chmod=20
777 ../../artikel". But I get weird displayed message:
"
ueri: ------------4CyrMz2ZeGIClwYfFsVdcv Co........
î 6êÎ]Ë kšfþx·¾ =
ðfS4M3>º {½â€=A1<Óöù³®ï¿=BD=
¯3çýGèBù=3D „¬È›øR=
ƒ.....
&ƒ ÿƒ&m‡îÃ=B8'-n nÊÐJ(pÇ 9=C3=
=A7qîÎ.........
Ê ¨‚¡ÀÃ=9C EÖ�Ã=82 z!ª=CB=
=9CY6�¬úÒ„â0J¼=E2=8 0œÃ±Ã=
=8B.......
[end so on. very longg.............]
".

And no file copied/uploaded in '../../artikel'. But inserting the record on=
to=20
the mysql run properly.

Please tell me why.....

Here I have done:
deartikel.cgi-->cgideartikel.cgi-->cgiuploadfile.cgi ('-->' means 'calls').
===3D
deartikel.cgi:
=2D--
#!/usr/bin/perl -w
#use strict;
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);

print "Content-type: text/html\n\n";
print "";
print "";
print "";
print "";
print "

";
print "Title of file autocomplete=3D\"ON\"> ";
print "

print " ";
print "";
print "";
===3D
cgideartikel.cgi:
=2D--
#!/usr/bin/perl -w
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use DBI;

print "Content-type: text/html\n\n";
print "";
print "";
print "";<br /> print "Online Science Org - Data entry kolom karir.";<br /> print "";
print "";
print "";
$pjg=3D$ENV{"CONTENT_LENGTH"};
read(STDIN, $kueri, $pjg);
#print "kueri: $kueri
";
@arr_prm=3Dsplit("&",$kueri);
foreach $myprm(@arr_prm){
($namavar,$nilaivar)=3Dsplit("=3D",$myprm);
$assprm{$namavar}=3D$nilaivar;
}
$i=3D0;
foreach my $nv(keys %assprm){
print "$nv
";
print "$assprm{$nv}
";
print "i =3D $i
";
$i++;
}

$judul=3D$assprm{'judul'};
print "
enctype=3D\"multipart/form-data\"> ";
print "Judul =3D\"ON\"=20
value=3D\"$judul\" readonly> ";
print "File untuk di-upload";
print " \"> ";
print "
";
print "
";
print "";
print "";
&simpan(judul);

sub simpan{
my $myjudul=3Dshift;
my $box=3D"localhost";
my $basisdata=3D"mydb";
my $db_user_name=3D'root';
my $db_password=3D'mypw';
my $dsn=3D"DBI:mysql:$basisdata:$box";

my $dbh =3D DBI->connect($dsn, $db_user_name, $db_password);
my $sqlstr=3Dqq{
insert into=20
artikel (
judul,
)
values(
'$myjudul'
)
};
my $sth =3D $dbh->prepare($sqlstr);
my $status=3D$sth->execute();
if($status){
$sth->{Commit};
}else{
$sth->{RollBack};
}
$dbh->disconnect;
}
=2D--
cgiuploadfile.cgi:
=2D--
#!/usr/bin/perl -w
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
print "Content-type: text/html\n\n";
print "";
print "";
print "";<br /> print "Online Science Org - Data entry kolom karir.";<br /> print "";
print "";
print "";

$pjg=3D$ENV{"CONTENT_LENGTH"};
read(STDIN, $kueri, $pjg);
print "kueri: $kueri
";
exit;
@arr_prm=3Dsplit("&",$kueri);
foreach $myprm(@arr_prm){
($namavar,$nilaivar)=3Dsplit("=3D",$myprm);
$assprm{$namavar}=3D$nilaivar;
}
$i=3D0;
foreach my $nv(keys %assprm){
print "$nv
";
print "$assprm{$nv}
";
print "i =3D $i
";
$i++;
}

$judul=3D$assprm{'judul'};
$url=3D$assprm{'url'};
print "
enctype=3D\"multipart/form-data\"> ";
print " ON\"=20
value=3D\"$judul\" readonly> ";
print "File untuk di-upload";
print " \"=20
readonly> ";
print " abled>
";
print "
";
print "";

my $output_file =3D "../../artikel/$url";
my ($bytesread, $buffer);
my $numbytes =3D 2000;
open (OUTFILE, ">", "$output_file")=20
or die "Couldn't open $output_file for writing: $!";
while ($bytesread =3D read($url, $buffer, $numbytes)) {
print OUTFILE $buffer;
}
close OUTFILE;

print "";
print "
";
print "";
=2D-=20
Patrik Hasibuan
Junior Programmer
http://www.penguin-teknologi.com
=2D-=20
Patrik Hasibuan
Junior Programmer
http://www.penguin-teknologi.com

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: perl for uploading file shows weird characters.

am 13.01.2008 00:31:06 von Gunnar Hjalmarsson

[ please do not multi-post! ]

Patrik Hasibuan wrote:
> 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>º {½‡<Óöù³®�¯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:

Well, the code you posted is far too much to my taste. Please post a
_small_ but complete program that illustrates the problem you are having.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
To unsubscribe, e-mail: beginners-cgi-unsubscribe@perl.org
For additional commands, e-mail: beginners-cgi-help@perl.org
http://learn.perl.org/