auFile

From auWiki
(Redirected from PHP:Class:auFile)
Jump to navigation Jump to search

The auFile class is part of the auLib package. Its purpose is to provide functions for dealing with files.

Usage

All functions in auFile are static, which means they can only be called in the form auFile::Function().

Constants

Allowed Image Upload Types

  • _AU_FILE_IMAGE_PNG
  • _AU_FILE_IMAGE_JPEG
  • _AU_FILE_IMAGE_GIF
  • _AU_FILE_IMAGE_ANY

Public Functions

Size

Size($file)

Formats the size of a file in an easy-to-read format.

  • $file = Full path to the file.
  • @return = File size in easy-to-read format.

ImageSize

ImageSize($file)

Formats the size of an image file in an easy-to-read format.

  • $file = Full path to the image file.
  • @return = Image file size in easy-to-read format.

ImageSizeCSS

ImageSizeCSS($file)

Formats the size of an image file into a CSS style attribute.

  • $file = Full path to the image file.
  • @return = CSS style attribute with image size.

NiceName

NiceName($name)

Makes sure a filename is fit for being on a web server. Specifically, this means anything not alphanumeric, underscores, dashes, or periods will be removed.

  • $name = Filename which may not be fit for a web server.
  • @return = Filename which definitely is fit for a web server.

SaveUpload

SaveUpload($fieldname, $savedir, $type, $savename, $maxsize)

Saves an uploaded file.

  • $fieldname = Name of the input field in the HTML form that submitted this file.
  • $savedir = Directory to save file in.
  • $type = MIME types allowed by this upload field. Default is to allow all MIME types.
  • $savename = Filename to save file as. Start with a dot to keep the uploaded name but change the extension. End with a dot to keep the uploaded extension. Filenames are always run through NiceName(). Default is to use the uploaded name and extension.
  • $maxsize = Maximum size for uploaded file (in bytes). Default is unlimited.
  • @return = True if file was saved, or an error message.

SaveUploadImage

SaveUploadImage($fieldname, $savedir, $type, $savename, $maxwidth, $maxheight, $scale, $maxsize, $savegifaspng, $keepaspect)

Saves an uploaded image file file.

  • $fieldname = Name of the input field in the HTML form that submitted this file.
  • $savedir = Directory to save file in.
  • $type = Image types allowed by this upload field (see _AU_FILE_IMAGE_* constants). Default is to allow all image types (PNG, JPEG, and GIF).
  • $savename = Filename to save file as. Extensions are always set according to the type of the uploaded file. Default is to use the uploaded name.
  • $maxwidth = Maximum width of the image (in pixels). Default is unlimited.
  • $maxheight = Maximum height of the image (in pixels). Default is unlimited.
  • $scale = If maximum width and/or height are specified and this is true, the image will be scaled down so that it fits within the maximum(s).
  • $maxsize = Maximum size for uploaded file (in bytes). Default is unlimited.
  • $savegifaspng = If true, GIF uploads will be converted to PNG.
  • $keepaspect = If false, uploaded image will be resized to exactly the maximum width and height.
  • @return = Array with result information:
    • ['found'] = True if a file was uploaded.
    • ['saved'] = True if image was saved.
    • ['message'] = Why the image wasn't saved if it wasn't saved.
    • ['size'] = Size of the image if it was saved.
    • ['width'] = Width of the image if it was saved.
    • ['height'] = Height of the image if it was saved.