QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1161|回复: 1

perl的上传文件

[复制链接]
发表于 2003-11-4 12:59:28 | 显示全部楼层 |阅读模式
小弟写了一个用perl上传文件的小程序:
use CGi;
use fcntl qw (:DEFAULT :flock );
use constant UPLOAD_DIR =>'C:\ProgramFiles\ApacheGroup\Apache\htdocs\img';
use constant BUFFER_SIZE =>1024;

my $q=new CGI;
$q->cgi_error and error($q,"Error transferring file:". $q->cgi_error);
my $file =$q->param("file") || error($q,"No file received");
my $filename =$q->param("filename") || error($q,"No filename entered");
my $fh =$q->upload($file);
my $buffer ="";
$filename=~s/[^\w.-]/_/g;

if($filename=~/^(\w[\w.-]*)/)
{
$filename=$1;

}
else
{
error($q,"Invalid file name;files must start with a letter or number");
}

$outputfile=UPLOAD_DIR."\\".$filename;
#print $outputfile;
if (!open(OUTPUT,">$outputfile"))
{
error($q,$outputfile);

}

while(read($fh,$buffer,BUFFER_SIZE))
{
binmode $fh;
binmode OUTPUT;
print OUTPUT $buffer;
}

close OUTPUT;
print $q->header("text/html");
print $q->start_html("success");
print $q->h1("upload success");
print $q->end_html;
exit;
sub error
{
my ($q,$reason)=@_;

print $q->header("text/html");
print $q->start_html("Error");
print $q->h1("Error");
print $q->p("Your upload was not procesed because the following error occured");
print $q->p($q->i($reason));
print $q->end_html;
exit;

}

发现用这个程序上传的文件字节数位0,不知为啥,请各位大侠指教
发表于 2003-11-10 16:16:41 | 显示全部楼层
HTML部分呢?
PHP里上传文件要给有文件框的 form 加参数 ENCTYPE="multipart/form-data"
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-11-23 03:37 , Processed in 0.123054 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表