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


In reply to WWW::Mechanize::Firefox and input type file by nicko.martin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.