Server IP : 127.0.0.2 / Your IP : 3.144.250.2 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/share/doc/libcgi-pm-perl/examples/ |
Upload File : |
#!/usr/bin/env perl use strict; use warnings; use CGI; use CGI::Carp qw/ fatalsToBrowser /; use Template; my $cgi = CGI->new; my $template_vars = { cgi_version => $CGI::VERSION, }; # Process the form if there is a file name entered if ( my $file = $cgi->param( 'filename' ) ) { my $tmpfile = $cgi->tmpFileName( $file ); my $mimetype = $cgi->uploadInfo( $file )->{'Content-Type'} || ''; @{$template_vars}{qw/file temp_file mimetype/} = ( $file,$tmpfile,$mimetype ); my %wanted = map { $_ => 1 } $cgi->multi_param( 'count' ); while ( <$file> ) { $template_vars->{lines}++ if $wanted{"count lines"}; $template_vars->{words} += split(/\s+/) if $wanted{"count words"}; $template_vars->{chars} += length if $wanted{"count chars"}; } close( $file ); } print $cgi->header( -type => 'text/html', -charset => 'utf-8', ); my $tt = Template->new; $tt->process( \*DATA,$template_vars ) or warn $tt->error; __DATA__ <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>File Upload Example</title> </head> <body> <b>Version</b> [% cgi_version %] <h1>File Upload Example</h1> <p>This example demonstrates how to prompt the remote user to select a remote file for uploading.</p> <p>Select the <cite>browser</cite> button to choose a text file to upload.</p> <p>When you press the submit button, this script will count the number of lines, words, and characters in the file.</p> <form method="post" action="file_upload" enctype="multipart/form-data">Enter the file to process: <input type="file" name="filename" size="45" /><br /> <label><input type="checkbox" name="count" value="count lines" checked="checked" />count lines</label> <label><input type="checkbox" name="count" value="count words" checked="checked" />count words</label> <label><input type="checkbox" name="count" value="count chars" checked="checked" />count characters</label> <input type="reset" name=".reset" /> <input type="submit" name="submit" value="Process File" /> <input type="hidden" name=".cgifields" value="count" /> </form> <hr /> [% IF file.defined %] <h2>[% file %]</h2> <h3>[% temp_file %]</h3> <h4>MIME Type: <i>[% mime_type %]</i></h4> <b>Lines: </b>[% lines %]<br /> <b>Words: </b>[% words %]<br /> <b>Characters: </b>[% chars %]<br /> [% END %] </body> </html>