1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Perl: ファイルのアップロード (cgi)

Last updated at Posted at 2021-04-11

こちらと同じことを Perl で実装しました。
Python3: ファイルのアップロード (cgi)
複数のファイルを同時にアップロードできます。
upload_perl.png

upload_perl.html
<!DOCTYPE html>
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>upload perl (Apr/11/2021)</title>
</head>
<body>
<h2>HTML5</h2>
<form method="post" action="upload_perl.pl" enctype="multipart/form-data">
<input type="file" name="files"  multiple>
<p><input type="submit" value="送信する"></p>
</form>
<p>Files will be uploaded to /tmp.</p>
<hr />
<p>Apr/11/2021 AM 08:25</p>
</body>
</html>
upload_perl.pl
# ! /usr/bin/perl

use	strict;
use	utf8;
use	warnings;
use	CGI;
use	File::Copy;

# --------------------------------------------------------------------
my $SAVE_DIR = '/tmp';

my $q = CGI->new;
my @files = $q->param ('files');
print "Content-type: text/html\n\n";
for my $filename (@files)
{
	copy($q->tmpFileName($filename), "$SAVE_DIR/$filename") or die $!;
	print $filename . "<br />";
}

print	"Data is saved<br />";
#
exit;

# --------------------------------------------------------------------
1
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?