473,396 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Bad file Descriptor

rajiv07
141 100+
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.

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use CGI;
  3. use CGI::Carp qw(fatalsToBrowser);
  4. use File::Basename;
  5. use diagnostics;
  6. $CGI::POST_MAX = 1024 * 1000; 
  7. $CGI::DISABLE_UPLOADS = 0;  
  8. my $query=new CGI;
  9.  
  10. my $file = $query->param("file") ;
  11. my $upload_dir = "../templates/";
  12.  
  13. my $filename_characters = 'a-zA-Z0-9_.-';
  14.  
  15. my $file = $query->param('file') ;
  16.  
  17. $file=~ s/(^\s+|\s+$)//;
  18.  
  19. my @array=();
  20.  
  21.  my ($filename,undef,$ext) = fileparse($file,qr{\..*});
  22.  
  23. $filename .= $ext;
  24.  
  25. $filename =~ tr/ /_/;
  26.  
  27. $filename =~ s/[^$filename_characters]//g;
  28.  
  29. if($filename =~ /^([$filename_characters]+)$/) {
  30.    $filename = $1;
  31. }
  32. else{
  33.    error("The filename is not valid. Filenames can only contain these characters: $filename_characters");
  34. }
  35.  
  36. ##I got the error in this line ##
  37.  
  38. my $upload_filehandle = $query->upload("file") or die $!;
  39.  
  40. open (UPLOADFILE, ">$upload_dir/$filename") or error($!);
  41. binmode UPLOADFILE;
  42. while ( <$upload_filehandle> ) {
  43.    print UPLOADFILE;
  44. }
  45. close UPLOADFILE;
  46. sub error {
  47.    print $query->header(),
  48.          $query->start_html(-title=>'Error'),
  49.          shift,
  50.          $query->end_html;
  51.    exit(0);
  52. }
Regards
Rajiv
May 28 '08 #1
5 4312
numberwhun
3,509 Expert Mod 2GB
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.

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use CGI;
  3. use CGI::Carp qw(fatalsToBrowser);
  4. use File::Basename;
  5. use diagnostics;
  6. $CGI::POST_MAX = 1024 * 1000; 
  7. $CGI::DISABLE_UPLOADS = 0;  
  8. my $query=new CGI;
  9.  
  10. my $file = $query->param("file") ;
  11. my $upload_dir = "../templates/";
  12.  
  13. my $filename_characters = 'a-zA-Z0-9_.-';
  14.  
  15. my $file = $query->param('file') ;
  16.  
  17. $file=~ s/(^\s+|\s+$)//;
  18.  
  19. my @array=();
  20.  
  21.  my ($filename,undef,$ext) = fileparse($file,qr{\..*});
  22.  
  23. $filename .= $ext;
  24.  
  25. $filename =~ tr/ /_/;
  26.  
  27. $filename =~ s/[^$filename_characters]//g;
  28.  
  29. if($filename =~ /^([$filename_characters]+)$/) {
  30.    $filename = $1;
  31. }
  32. else{
  33.    error("The filename is not valid. Filenames can only contain these characters: $filename_characters");
  34. }
  35.  
  36. ##I got the error in this line ##
  37.  
  38. my $upload_filehandle = $query->upload("file") or die $!;
  39.  
  40. open (UPLOADFILE, ">$upload_dir/$filename") or error($!);
  41. binmode UPLOADFILE;
  42. while ( <$upload_filehandle> ) {
  43.    print UPLOADFILE;
  44. }
  45. close UPLOADFILE;
  46. sub error {
  47.    print $query->header(),
  48.          $query->start_html(-title=>'Error'),
  49.          shift,
  50.          $query->end_html;
  51.    exit(0);
  52. }
Regards
Rajiv
In line 38, shouldn't "file" be "$file"?

Regards,

Jeff
May 28 '08 #2
KevinADC
4,059 Expert 2GB
Change this line:

Expand|Select|Wrap|Line Numbers
  1. open (UPLOADFILE, ">$upload_dir/$filename") or error($!);
change to:

Expand|Select|Wrap|Line Numbers
  1. 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.
May 28 '08 #3
KevinADC
4,059 Expert 2GB
In line 38, shouldn't "file" be "$file"?

Regards,

Jeff
Short answer is: no.
May 28 '08 #4
numberwhun
3,509 Expert Mod 2GB
Short answer is: no.
That's what I get for digging through tons of code all day. :)
May 28 '08 #5
rajiv07
141 100+
Change this line:

Expand|Select|Wrap|Line Numbers
  1. open (UPLOADFILE, ">$upload_dir/$filename") or error($!);
change to:

Expand|Select|Wrap|Line Numbers
  1. 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
May 29 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
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...
3
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...
9
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...
2
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...
2
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...
3
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...
0
ashitpro
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...
3
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...
3
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...
9
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.