クロスポストhttp://perlmonks.org/?node_id=981067
WWW::Mechanize::Firefox を使用して、次のような入力タイプのファイルを使用するフォームを使用してファイルをサイトにアップロードする際に問題があります。
<form enctype="multipart/form-data" action="uploader.php" method="POST" id="formular">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="image0" type="file" id="image0"/><br />
<input type="submit" value="Upload File" />
uploader.php の内容は次のとおりです。
<?php
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['image0']['name']);
if(move_uploaded_file($_FILES['image0']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['image0']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file,". basename( $_FILES['image0']['name'])." please try again!";
}
?>
ファイルのアップロードに使用するコードは次のとおりです。
#!/usr/bin/perl
use strict;
use warnings;
use WWW::Mechanize::Firefox;
my $bot = WWW::Mechanize::Firefox->new( autoclose => 0,activate =>1);
$bot->get('http://127.0.0.1/file/index.html');
$bot->form_id('formular');
$bot->field('image0','IMAGE.JPG');
$bot->submit;
実行時にエラーは発生せず、フォームは送信されますが、image0 には何もありません。
私が使用している WWW::Mechanize::Firefox のバージョンは 0.66 です 私の perl のバージョンは : MSWin32-x86-multi-thread 用にビルドされた v5.10.0 です
ありがとう