Home > Archive > PERL Beginners > August 2005 > upload question
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Cristi Ocolisan 2005-08-22, 7:55 am |
| Hi all,
Does anybody know why this code does NOT copying the file into the specified
directory?
After the script is executed, my file is listed into the directory, but
empty.
Strange?
my $upload_dir = "../../witp/sigle_firme";
my $max_size = 1024_000;
my $file_name;
if ( length($sigla) > 0 ) {
( $file_name = $sigla ) =~ s/.*\\//;
my $upload_path = "$upload_dir/$file_name";
open (OUT, ">$upload_path") or die "Error opening $upload_path: $!";
binmode OUT;
my $buffer = '';
my $size = 0;
while (my $chars_read = read($sigla, $buffer, 4096)) {
print OUT $buffer;
$size += $chars_read;
if ( $size > $max_size ) {
last;
}
}
close OUT;
if ( -z $upload_path or $size > $max_size ) {
unlink $upload_path;
}
}
It is strange because I wrote this code earlier and it was working
perfectly.
Please make me understand why it does not want to work anymore :-).
Thanks.
CO
| |
| David Aldridge 2005-08-22, 7:56 am |
| If this is the full code, you do not assign a value to $sigla is the first
thing that I see.
_____
From: Cristi Ocolisan [mailto:cristi@wiq.ro]
Sent: Monday, August 22, 2005 5:20 AM
To: beginners@perl.org
Subject: upload question
Hi all,
Does anybody know why this code does NOT copying the file into the specified
directory?
After the script is executed, my file is listed into the directory, but
empty.
Strange?
my $upload_dir = "../../witp/sigle_firme";
my $max_size = 1024_000;
my $file_name;
if ( length($sigla) > 0 ) {
( $file_name = $sigla ) =~ s/.*\\//;
my $upload_path = "$upload_dir/$file_name";
open (OUT, ">$upload_path") or die "Error opening $upload_path: $!";
binmode OUT;
my $buffer = '';
my $size = 0;
while (my $chars_read = read($sigla, $buffer, 4096)) {
print OUT $buffer;
$size += $chars_read;
if ( $size > $max_size ) {
last;
}
}
close OUT;
if ( -z $upload_path or $size > $max_size ) {
unlink $upload_path;
}
}
It is strange because I wrote this code earlier and it was working
perfectly.
Please make me understand why it does not want to work anymore :-).
Thanks.
CO
|
|
|
|
|