Typically a regexp is what you would use to validate/filter form data. The cryptic looking part of that code, ($file =~ /^(\w \.\w )$/), is called a regular expression (regexp). Note: I use command and method interchangeably throughout the article to mean the same thing.Įrror('Invalid characters in filename.') “413” indicates the limit we set for $CGI::POST_MAX has been exceeded, so we are going to check for that response. We give the cgi_error() command to our trusty butler “$q” and he returns a response, $error. The first is going to check the amount of data sent to the script. We are going to use three “checkpoints” to detect any suspicious activity. Never underestimate the need for security when running scripts as a CGI. I recommend you take the time to read the CGI modules documentation, even if you don’t understand much of it, you should at least be familiar with the basic form processing methods. Just like a real butler you have to trust that he knows what he is doing and will get the job done efficiently and effectively without looking over his shoulder. But the beauty is you only need to know what the commands do, not how they do it. Learning to use the CGI module is almost like learning a small programming language. In reality, the CGI module has many “commands” you can give to the “butler”. Our “butler”, $q, will know what to do with the “commands” we will give him. You tell the butler what you want and he knows how to get it done, you don’t have to worry about the details. $q is the object we will use to execute various methods of the CGI module. $url should be the name of your website including the “ part. $error_log is the path to the errors.txt file that logs errors generated by the script. This is commonly done by putting them in a folder parallel to your root web folder (public_html or www) or above it. I recommend you store them in a folder that is not web accessible. $path_to_files is the directory where you store the files to be downloaded. My $error_log = '/home/user/downloads/logs/errors.txt' # Preferably this should be above the web root folder. # The path to where the downloadable files are. Just about all perl scripts that run as a CGI process need to start with what is called the shebang line. The folder where you upload the script to and the permissions may be different for your server. Typically you would upload the script into your cgi-bin folder and set the file permissions to 755. A little bit of prior HTML knowledge would be helpful but is not necessary. A server that allows you to store files above the web root is preferable but not necessary. I’m going to show you how to do that using a perl script.Īny recent version of perl (5.06 or newer should be good) and a server to run the script on. You click a form button or click on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. Many websites have a form or a link you can use to download a file. Note: You may skip to the end of the article if all you want is the perl code.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |