Hi i have script for upload file to server.when i execute this script it gives Bad file Descriptor error.could u anybody help on this. -
use strict;
-
use CGI;
-
use CGI::Carp qw(fatalsToBrowser);
-
use File::Basename;
-
use diagnostics;
-
$CGI::POST_MAX = 1024 * 1000;
-
$CGI::DISABLE_UPLOADS = 0;
-
my $query=new CGI;
-
-
my $file = $query->param("file") ;
-
my $upload_dir = "../templates/";
-
-
my $filename_characters = 'a-zA-Z0-9_.-';
-
-
my $file = $query->param('file') ;
-
-
$file=~ s/(^\s+|\s+$)//;
-
-
my @array=();
-
-
my ($filename,undef,$ext) = fileparse($file,qr{\..*});
-
-
$filename .= $ext;
-
-
$filename =~ tr/ /_/;
-
-
$filename =~ s/[^$filename_characters]//g;
-
-
if($filename =~ /^([$filename_characters]+)$/) {
-
$filename = $1;
-
}
-
else{
-
error("The filename is not valid. Filenames can only contain these characters: $filename_characters");
-
}
-
-
##I got the error in this line ##
-
-
my $upload_filehandle = $query->upload("file") or die $!;
-
-
open (UPLOADFILE, ">$upload_dir/$filename") or error($!);
-
binmode UPLOADFILE;
-
while ( <$upload_filehandle> ) {
-
print UPLOADFILE;
-
}
-
close UPLOADFILE;
-
sub error {
-
print $query->header(),
-
$query->start_html(-title=>'Error'),
-
shift,
-
$query->end_html;
-
exit(0);
-
}
Regards
Rajiv
5 4312
Hi i have script for upload file to server.when i execute this script it gives Bad file Descriptor error.could u anybody help on this. -
use strict;
-
use CGI;
-
use CGI::Carp qw(fatalsToBrowser);
-
use File::Basename;
-
use diagnostics;
-
$CGI::POST_MAX = 1024 * 1000;
-
$CGI::DISABLE_UPLOADS = 0;
-
my $query=new CGI;
-
-
my $file = $query->param("file") ;
-
my $upload_dir = "../templates/";
-
-
my $filename_characters = 'a-zA-Z0-9_.-';
-
-
my $file = $query->param('file') ;
-
-
$file=~ s/(^\s+|\s+$)//;
-
-
my @array=();
-
-
my ($filename,undef,$ext) = fileparse($file,qr{\..*});
-
-
$filename .= $ext;
-
-
$filename =~ tr/ /_/;
-
-
$filename =~ s/[^$filename_characters]//g;
-
-
if($filename =~ /^([$filename_characters]+)$/) {
-
$filename = $1;
-
}
-
else{
-
error("The filename is not valid. Filenames can only contain these characters: $filename_characters");
-
}
-
-
##I got the error in this line ##
-
-
my $upload_filehandle = $query->upload("file") or die $!;
-
-
open (UPLOADFILE, ">$upload_dir/$filename") or error($!);
-
binmode UPLOADFILE;
-
while ( <$upload_filehandle> ) {
-
print UPLOADFILE;
-
}
-
close UPLOADFILE;
-
sub error {
-
print $query->header(),
-
$query->start_html(-title=>'Error'),
-
shift,
-
$query->end_html;
-
exit(0);
-
}
Regards
Rajiv
In line 38, shouldn't "file" be "$file"?
Regards,
Jeff
Change this line: - open (UPLOADFILE, ">$upload_dir/$filename") or error($!);
change to: - open (UPLOADFILE, ">$upload_dir$filename") or error($!);
you already have a trailing slash on the end of $upload_dir as defined in line number eleven of the code you posted.
In line 38, shouldn't "file" be "$file"?
Regards,
Jeff
Short answer is: no.
Short answer is: no.
That's what I get for digging through tons of code all day. :)
Change this line: - open (UPLOADFILE, ">$upload_dir/$filename") or error($!);
change to: - open (UPLOADFILE, ">$upload_dir$filename") or error($!);
you already have a trailing slash on the end of $upload_dir as defined in line number eleven of the code you posted.
Thanks Kevin.Its working fine.I have spent 1 hour to sort this but i couldn't find the small mistake.
Regards
Rajiv
Sign in to post your reply or Sign up for a free account.
Similar topics
by: pembed2003 |
last post by:
Hi all,
Given something like:
std::ofstream out_file("path");
how do I extract the file descriptor from out_file? Is it possible?
What I want is to extract the file descriptor and then pass...
|
by: gipsy boy |
last post by:
Given a file descriptor (from a network socket, for instance), I want to
have an iostream that reads/writes to it, so I can push and read data in
the traditional way :
sockStream << "<some...
|
by: Ben Dewey |
last post by:
Project:
----------------------------
I am creating a HTTPS File Transfer App using ASP.NET and C#. I am
utilizing ActiveDirectory and windows security to manage the
permissions. Why reinvent...
|
by: John Regan |
last post by:
Hello All
I am trying to find the owner of a file or folder on our network (Windows
2000 Server) using VB.Net and/or API. so I can search for Folders that don't
follow our company's specified...
|
by: levimc |
last post by:
I know that that topic may be old to you but I looked at other more-
than-two-year-old topics
related to mine. However, I didn't find them working for my project
at all because its errors return...
|
by: Yang |
last post by:
Hi, I'm experiencing a problem when trying to close the file descriptor
for a socket, creating another socket, and then closing the file
descriptor for that second socket. I can't tell if my issue...
|
by: ashitpro |
last post by:
As per the last discussion(chapter 1), here we'll try to read the group descriptor.
First of all we'll try to understand what is group descriptor.
AS we know, superblock and group descriptor table...
|
by: sejal17 |
last post by:
hello
Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
|
by: sejal17 |
last post by:
hello
Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
|
by: Bill David |
last post by:
I know it's very strange to do that since we have the file name when
we call:
int open(const char *pathname, int oflag,...);
And we can store the file name for later usage.
But I just wonder if...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |