Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Journal of markjugg (792)

Saturday April 24, 2004
09:30 PM

CGI::Uploader - a new module to ease file upload mgmt.

[ #18472 ]

So I've been hacking a lot on a new file upload module and am ready to get some feedback on it on it. An introduction is below. You can also browse the documentation, or check out some recipes for a complete application. Feedback appreciated!

CGI::Uploader is designed to help with the task of managing files uploaded through a CGI application. The files are stored on the file system, and the file attributes stored in a SQL database.

A Little History

The release of this module represents a culmination of seven years of experience mananging file uploads as a professional website developer for Summersault, LLC ( Over that time I noticed patterns that were re-usable from project to project. I went through serveral versions and rewrites of modules that attempted to be 'generic' and not need modification when the next project came along. With CGI::Uploader, I believe I finally have a solution that I will continue to be happy with and I think others will be find generally useful. Enjoy!

Freedom of Choice

I have strived to make CGI::Uploader to work within a variety of system designs. It offers you freedom choice in the following areas:

  • Database Choice

    MySQL and Postgres are supported directly. The SQL used is very simple-- support for additional databases should be trivial.

  • Choice of Query Provider

    The query object used may provided by, CGI::Simple or Apache::Request. Another source could be used by overriding the upload method.

  • File Storage Schemes for Large and Small Projects

    For small projects, all uploads can be stored in a single directory. For large projects, we provide the md5 file scheme, which should scale well to millions of images, without burdening any single directory with storing too many of them.

  • Choice of Data Display

    Because the meta data is stored in a straightforward SQL database table, you can retrieve your data and display in any number of custom ways. Several functions are also built in to help with common display tasks. The build_loc() method is used to construct the file system or URL path of an image, given it's ID and extension.

    fk_meta() provides an easy way to get the meta data of an upload by relating it to a foreign key in another table.

    Finally, transform_meta() is a basic function which tranforms a hashref of data from the database into a format more useful for display, producing a hash that looks like this:

    my_id     => 523,
    my_url    => http://localhost/images/uploads/523.pdf?32,
    my_width  => 23,
    my_height => 46,

  • Image Processor

    While CGI::Uploader works with all types of file uploads, it contains a number of features to help with common tasks associated with image uploads.

    Image::Magick is the preferred image processing module for to use when creating the thunbmails. Support for GD is in progress. GD supports many fewer formats, but also has much fewer dependencies to get installed than Image::Magick does. Another providers could be used by extending or overriding the gen_thumb() method.

Just Three Essential Methods to Learn

A goal of CGI::Uploader; is to provide a high-level interface to make managing file uploads easy. Only three methods are needed to manage all the functions needed to store, update, delete and view the uploads attached to sme database entity. Those methods are store_uploads(), delete_checked_uploads() and fk_meta.

More methods when you need them

When your needs before more complex, you can call the lower-level functions in CGI::Uploader to meet your needs. Most functions use file names to access file uploads, so it's easy to use the module to manipulate files from other sources than the browser upload field.

For example, the gen_thumb() method is general purpose thumbnail creating routine.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.