GX::HTTP::Upload

Module Version: 0.2000_01

NAME

GX::HTTP::Upload - HTTP upload class

SYNOPSIS

# Load the class
use GX::HTTP::Upload;

# Create a new upload object
$upload = GX::HTTP::Upload->new( '/tmp/0001.jpg' );

# Get the size in bytes of the upload
$bytes = $upload->size;

# Get the accompanying headers
$headers = $upload->headers;

# Get the name of the associated HTML form control
$name = $upload->name;

# Move the uploaded file
$upload->move( '/myapp/uploads/0001.jpg' );

# Disable file deletion on object destruction
$upload->cleanup( 0 );

DESCRIPTION

This module provides the GX::HTTP::Upload class which extends the GX::Class::Object class.

METHODS

Constructor

new

Returns a new GX::HTTP::Upload object.

$upload = GX::HTTP::Upload->new( %attributes );
Attributes:
  • cleanup ( bool )

    A boolean flag indicating whether or not to delete the uploaded file on destruction of the upload object. Defaults to true.

  • file ( string )

    The path to the uploaded file.

  • filename ( string )

    The client-supplied name of the uploaded file.

  • headers ( GX::HTTP::Headers object )

    A GX::HTTP::Headers object containing the headers that accompanied the upload.

  • name ( string )

    The name of the HTML form control associated with the upload.

Returns:
Exceptions:

Alternative syntax:

$upload = GX::HTTP::Upload->new( $file );
Arguments:
  • $file ( string )

    The path to the uploaded file.

Returns:
Exceptions:

Public Methods

cleanup

Returns / sets the cleanup flag.

$bool = $upload->cleanup;
$bool = $upload->cleanup( $bool );
Arguments:
  • $bool ( bool ) [ optional ]
Returns:
  • $bool ( bool )

file

Returns / sets the path to the uploaded file.

$file = $upload->file;
$file = $upload->file( $file );
Arguments:
  • $file ( string | undef ) [ optional ]
Returns:
  • $file ( string | undef )

filename

Returns / sets the client-supplied name of the uploaded file.

$filename = $upload->filename;
$filename = $upload->filename( $filename );
Arguments:
  • $filename ( string | undef ) [ optional ]
Returns:
  • $filename ( string | undef )

headers

Returns / sets the container object for the headers that accompanied the upload.

$headers = $upload->headers;
$headers = $upload->headers( $headers );
Arguments:
Returns:

move

Moves the uploaded file to the specified destination.

$upload->move( $destination, $overwrite );
Arguments:
  • $destination ( string )
  • $overwrite ( bool ) [ optional ]

    Defaults to false.

Exceptions:

Calling this method updates the file attribute and sets the cleanup flag to false.

name

Returns / sets the name of the HTML form control associated with the upload.

$name = $upload->name;
$name = $upload->name( $name );
Arguments:
  • $name ( string | undef ) [ optional ]
Returns:
  • $name ( string | undef )

open

Opens the uploaded file in the specified mode, returning an IO::File object on success.

$handle = $upload->open( $mode );
Arguments:
  • $mode ( string ) [ optional ]

    The open mode (">", "+<", etc.). If omitted, the file is opened in read-only mode.

Returns:
Exceptions:

size

Returns the size of the uploaded file in bytes.

$size = $upload->size;
Returns:
  • $size ( integer )

AUTHOR

Jörg A. Uzarek <uzarek@runlevelnull.de>

COPYRIGHT AND LICENSE

Copyright © 2009-2011 Jörg A. Uzarek.

This module is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License Version 3 as published by the Free Software Foundation.