1
交叉后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
感谢
在您当前的工作目录中是否有文件“IMAGE.JPG”?也许文件名不是大写? – simbabque 2012-07-11 15:19:02