CGI perl读取并打印文件的内容

时间:2013-06-21 06:04:16

标签: cgi perl-module

我想打开一个文本文件,并使用CGIPerl阅读前10行 我写了剧本,但它不起作用。我的问题在哪里

#!C:/wamp/apps/Perl/bin/perl.exe -wt

use CGI;
my $cgi=CGI->new();

print 
$cgi->header('text/html'),
$cgi->start_html('Extract the text'),
$cgi->h1({-style=>'color:red;background-color:#eee;'},'Extract CGI'),
$cgi->start_form(-enctype=>&CGI::MULTIPART),
'Upload your text File: ',
$cgi->filefield(
    -name=>'filename',
    ),
$cgi->submit(-value=>'Read the File'),

my $txtfile=$cgi->param('filename'),

open my $in,$filename or die("couldnot open");
while (my $line = <$in>)
{
    print $line;
    last if $. == 10;
}
close $in;

$cgi->end_form;
$cgi->end_html;

1 个答案:

答案 0 :(得分:0)

你可能会发现这个有用的

http://www.sitepoint.com/uploading-files-cgi-perl-2/

基本上,上传的文件名称与从浏览器传入的文件名称相同

您需要先检查先发送的内容

相关问题