Handling file uploading from www forms with CGI.pm
IntroductionNetscape Navigator 2.0 introduced a new facility for forms, the file upload element. This element allows the user to select a local file to be submitted with the form to the server that handles the form. File uploading is a frequently needed facility in many occasions, but the technique involved in handling forms that upload files is rarely discussed in CGI programming texts, and online tutorials/references on this topic are few. The technique is very simple as we shall see.
The formFirst of all we'll need to prepare the HTML form that will contain the file upload element:
The CGI scriptOn the server side, we'll have the CGI program (upload.pl) that will handle the upload. We will use CGI.pm that does all the dirty job for us. CGI.pm processes the submission of the form for us and provides us with a simple method of retrieving each individual part of the submission. In our case we only have one element, called file:
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'perlfect'@'18.104.22.168' (using password: YES) in /home/content/g/i/o/giorgoszervas/html/comments/comments_include.php on line 6
Connection Error: Access denied for user 'perlfect'@'22.214.171.124' (using password: YES)
Like it? Share it!
The Official CGI.pm Programming Guide is the definitive manual and guidebook for writing CGI programs with perl and the CGI library. While the manual distributed with the library as part of perl's documentation is well written and covers almost anything you'd need to know about using CGI.pm, this book is a useful companion for anyone making CGI scripts with perl.
CGI Programming is an introductry book for CGI programming, perhaps not the best book I've read. It covers most topics about the CGI protocol and how to write server side programs to work with it. Nevertheless, most if not all of the information in this book (as with most books that discuss CGI programming) can be found in tutorials and references on the web, but if you feel like buying a book anyway, you may want to consider this one.
Webmaster in a nutshell is a catch-all reference book for webmaster and programmers. It does not have anuything that you can't find online, but if you're liek me you might want to have all the stuff you refer to frequently nicely laid out in a well-organized book lying on your desk. If you're looking for something like that then you'll be happy with this book.
The Perl Cookbook is full of quick solutions to everyday programming problems in perl with explanations and tips easy to understand even for beginners, but also frequently useful even to more experienced programmers. The code is clear and straightforward and the topics covered as well-thought and correspond to real world examples, so frequently you can literally copy code snippets from the book and fit them in your program. It is a nice complement for the Camel Book on your bookshelf.