Author image Alexandre Masselot
and 1 contributors


CGI::FileUpload - A module to upload file through CGI asynchrnously, know where the upload status and get back the file from a third parties on the server



An uploaded file is associated with a key (corresponding to a file in a server temp directory)

When uploading is started the key is returned before the uploading completed, allowing further queries such as knowing is the upload is completed, uploaded file size etc...


    use CGI::FileUpload;

    my $fupload = CGI::FileUpload->new();




Returns the session upload directory (by default is $CGI_FILEUPLOAD_DIR or /defaulttempdir/CGI-FileUpload)


Returns a html <FORM> string such as <form name='cgi_fileupload' method='post' enctype='multipart/form-data'> <input type='file' name='uploadfile'/> <input type='hidden' name='action' value='upload'/> <input type='hidden' name='return_format' value='text'/> <input type='submit' value='upload'> </form>

Parameters can be of

submit_value=>string: the value displayed on the "submit button"
return_format=>(keyonly|text|json): the type of output at submission time (default is keyonly, but a text key=value perl line, but json should also be possible)
form_name=>string the form name (default is 'cgi_fileupload'


Either retrieves the id cookie or build one based one random number + ip



my $fupload=new CGI::FileUpload();

Creates a new instance in the temp directory

my $fupload=new CGI::FileUpload(suffix=>string);

Creates a file (thus returns a key)ending with .string

my $fupload=new CGI::FileUpload(key=>string);

Read info for an existing file being (or having been) uploaded.

Getting(/setting mor internal) info


returns the reference key


Returns the originated IP address


Returns some user id (hidden in a randomized cookie)


Returns a string '(uploading|completed|killed)'


Returns a Util::Properties object associated (containing status and whatever info


Returns the local file associated with the uploaded file


$fupload->upload() (query=>$cgi_query [,opts])

Start the upload. A CGI::query must be passed. Other optional arguments can be of

asynchronous=>(1|0) to see if the transfer must be completed before returning (0 value). default is 1;


Removes the file upload structure from the temp directory


Kill the uploading process (default signal is 'INT')


Alexandre Masselot, <alexandre.masselot at>


Please report any bugs or feature requests to bug-cgi-fileupload at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

    perldoc CGI::FileUpload

You can also look for information at:



Copyright 2007 Alexandre Masselot, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.