交叉发布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 版本是:v5.10.0 为 MSWin32-x86-multi-thread 构建
谢谢