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