Perl is general-purpose programming language, specially designed for text manipulation and in present time used for various task including system administration, web development, network programming, GUI development, and in other more area.
In Perl, CGI(Common Gateway Interface) is a protocol for executing scripts via web requests or in other words we can say it’s a set of rules and standards that define how information is exchanged between the custom script and Web Server.
At the Web server end, the software (in our case, a CGI script) interprets the form data that’s sent from the browser, and extracts the file name and contents, along with the other form fields. Usually, the file is then saved to a directory on the server.
Note: Following are the necessities to build a CGI Upload Script:
- Access to a CGI compatible Web Server
- A copy of Perl must be running on the Web server
- Your Web server must contain the Perl CGI Library, CGI.pm
Uploading a file on the Web Server is done with the use of a File upload Form. This File upload form is created on any text editor available and the form must be saved with .htm or .html extension. Creation of a File Upload form involves the following steps:
Step 1: Creating Form element
Firstly, there is a need to create a ‘form’ element
Note: In the above code, the multipart/form-data is the encoding type to be used for File Upload and the file upload.cgi is used to store the data posted using this form
Step 2: Creating Form fields
Secondly, we need to provide fields for the form. These fields are used to guide the user with the files that need to be uploaded in the form.
e.g. Here, we will provide an Upload field for the user to upload their photos and to provide their Email.
Step 3: Providing Submit Form button
Third Step is to allow the user to submit all the files uploaded according to the fields given in the form. For that, a submit button is required so that the user can send the form to the Web Server.
Example : Sample form to show the Working of File Upload in CGI:
- How to change the maximum upload file size in PHP ?
- Perl | Appending to a File
- Perl | File Locking
- Perl | Writing to a File
- Perl | File Test Operators
- Perl | File Handling Introduction
- Perl | Opening and Reading a File
- How to upload files asynchronously using jQuery?
- How to select and upload multiple files with HTML and PHP, using HTTP POST?
- Perl vs C/C++
- Perl | Hash
- Perl | int() function
- Perl | log() Function
- Perl | last in loop
- Perl vs Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.