nicko.martin has asked for the wisdom of the Perl Monks concerning the following question:

Hi everybody, I have a problem using WWW::Mechanize::Firefox to upload a file to a site with a form using an input type file, like this :

<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" />

The content of uploader.php is the following :

<?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!"; } ?>

And the code I use for uploading the file is the following :

#!/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;

There is no error at execution, and the form is submited but without nothing in image0.

The version of WWW::Mechanize::Firefox I use is 0.66 my perl version is : v5.10.0 built for MSWin32-x86-multi-thread

Thanks

Replies are listed 'Best First'.
Re: WWW::Mechanize::Firefox and input type file
by Corion (Patriarch) on Jul 11, 2012 at 10:31 UTC

    Uploading a file is currently not supported by Firefox, as I haven't found a good way of manipulating the File Picker or the underlying XUL elements to accept the file name.

    There is no real workaround either, sorry.

      Ok, thanks for your reply.