Perl的WWW ::机械化:: Firefox和输入类型的文件
问题描述:
交叉后http://perlmonks.org/?node_id=981067Perl的WWW ::机械化:: Firefox和输入类型的文件
我有使用WWW ::机械化:: 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;
执行时没有错误,并且表单被submited但image0中没有任何内容。
WWW的版本::机械化::火狐我用的是0.66我的Perl的版本是:对于MSWin32 86多线程构建v5.10.0
感谢
答
为什么不尝试添加全路径到图像文件,并在field()
方法东西键/值对等
my $image_path = "/home/images/IMAGE.JPG";
$bot->field(image0=>$image_path);
$bot->submit();
此外,假设WWW::Mechanize::Firefox
继承所有的LWP::UserAgents
方法,包括以下之前的代码10
$bot->add_handler("request_send", sub { shift->dump; return });
$bot->add_handler("response_done", sub { shift->dump; return });
这将启用日志记录在您的代码。注意日志文件中的请求和响应代码,如'HTTP 200 OK'或'HTTP 302 Found'。这些是标准的HTTP响应代码,因此您会知道您正在收到正确的回复。
在您当前的工作目录中是否有文件“IMAGE.JPG”?也许文件名不是大写? – simbabque 2012-07-11 15:19:02