LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1367|回复: 2

如何用perl制作图片上传???

[复制链接]
发表于 2004-6-5 18:03:18 | 显示全部楼层 |阅读模式
很多网站都允许用户自己上传图片,想问一下高手如何用perl写啊??
谢谢!!
发表于 2004-6-6 15:19:29 | 显示全部楼层
发表于 2004-6-6 15:35:08 | 显示全部楼层
[php]
#!/usr/local/bin/perl -w

use strict 'refs';
use lib '..';
use CGI qw(:standard);
use CGI::Carp qw/fatalsToBrowser/;

print header();
print start_html("File Upload Example");
print strong("Version "),$CGI::VERSION,p;

print h1("File Upload Example"),
    'This example demonstrates how to prompt the remote user to
    select a remote file for uploading. ',
    strong("This feature only works with Netscape 2.0 or greater, or IE 4.0 or greater."),
    p,
    'Select the ',cite('browser'),' button to choose a text file
    to upload.  When you press the submit button, this script
    will count the number of lines, words, and characters in
    the file.';

my @types = ('count lines','count words','count characters');

# Start a multipart form.
print start_multipart_form(),
    "Enter the file to process:",
    filefield('filename','',45),
    br,
    checkbox_group('count',\@types,\@types),
    p,
    reset,submit('submit','Process File'),
    endform;

# Process the form if there is a file name entered
if (my $file = param('filename')) {
    my %stats;
    my $tmpfile=tmpFileName($file);
    my $mimetype = uploadInfo($file)->{'Content-Type'} || '';
    print hr(),
          h2($file),
          h3($tmpfile),
          h4("MIME Type:",em($mimetype));

    my($lines,$words,$characters,@words) = (0,0,0,0);
    while (<$file>) {
        $lines++;
        $words += @words=split(/\s+/);
        $characters += length($_);
    }
    close $file;
    grep($stats{$_}++,param('count'));
    if (%stats) {
        print strong("Lines: "),$lines,br if $stats{'count lines'};
        print strong("Words: "),$words,br if $stats{'count words'};
        print strong("Characters: "),$characters,br if $stats{'count characters'};
    } else {
        print strong("No statistics selected.");
    }
}

# print cite("URL parameters: "),url_param();

print  end_html;

[/php]


注: 上面是 perl 代码,呵呵,不是 php 哟,只要存为 upload.cgi 就可以用了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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