Blesta
  • Package
  • Class
  • Tree
  • Deprecated

Packages

  • blesta
    • app
      • components
        • events
          • default
      • controllers
      • models
    • components
      • auth
      • delivery
        • interfax
        • postal
          • methods
      • download
      • email
      • exchange
        • rates
          • foxrate
          • google
            • finance
          • yahoo
            • finance
      • gateway
        • payments
      • gateways
      • invoice
        • delivery
        • templates
      • json
      • modules
      • net
        • http
        • net
          • amazon
            • s3
          • geo
            • ip
      • plugins
      • recaptcha
      • security
      • session
        • cart
      • settingscollection
      • upgrades
      • upload
      • vcard
    • helpers
      • currency
        • format
      • data
        • structure
          • array
          • string
      • text
        • parser
  • com
    • tecnick
      • tcpdf
        • blesta
          • components
            • invoice
              • templates
                • quickbooks
                  • invoice
                • templates
                  • default
  • Crypt
    • AES
    • DES
    • Hash
    • Random
    • RC4
    • Rijndael
    • RSA
    • TerraDES
  • File
    • ANSI
    • ASN1
    • X509
  • Math
    • BigInteger
  • minPHP
    • components
      • input
      • record
    • helpers
      • color
      • data
        • structure
      • date
      • html
      • xml
    • lib
  • Net
    • SFTP
    • SSH1
    • SSH2
  • None
  • PHP
  • PHPMailer
  • Services
    • JSON
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Upload

Class Upload

Upload component

Simplifies the file upload and storage for files added to the filesystem

Requires the Input Component

Package: blesta\components\upload
Copyright: Copyright (c) 2010, Phillips Data, Inc.
License: The Blesta License Agreement
Link: Blesta
Located at components/upload/upload.php

Methods summary

public
# __construct( )

Initialize the Upload

Initialize the Upload

public
# setFiles( array $files, boolean $uploaded_files = true )

Sets the array of files to be considered for handling. This class automatically defaults the set of arrays to the global FILES array

Sets the array of files to be considered for handling. This class automatically defaults the set of arrays to the global FILES array

Parameters

$files
array
$files An array of files from the global FILES array to set. The format of this array must match that the global FILES array exactly
$uploaded_files
boolean
$uploaded_file If true the file was uploaded, false if the file was created and not uploaded
public
# setUploadPath( string $path, mixed $create = false )

Sets the upload path. The upload path will be verified when files are written. If the upload path is invalid file uploads will result in errors

Sets the upload path. The upload path will be verified when files are written. If the upload path is invalid file uploads will result in errors

Parameters

$path
string
$path The server path to where files are to be written
$create
public
# setMaxFileSize( integer $bytes = 0 )

Sets the maximum file size in bytes. The server may have its own setting for maximum file sizes, so ensure that this value does not exceede the server's allowed maximum size

Sets the maximum file size in bytes. The server may have its own setting for maximum file sizes, so ensure that this value does not exceede the server's allowed maximum size

Parameters

$bytes
integer
$bytes The maximum file size in bytes. Set to 0 to use no maximum file size.
public
# setAllowedMimeTypes( array $types = null )

Sets the allowed MIME types

Sets the allowed MIME types

Parameters

$types
array
$types An array of MIME types to allow, set to null to allow all MIME types
public
# writeFile( string $file, boolean $overwrite = true, string $file_name = null, callable $rename_callback = null )

Writes one or more files to the file system. Because of the nature of writing files to the disk, if any file fails execution will continue. Any failed files will be reported by Upload::errors()

Writes one or more files to the file system. Because of the nature of writing files to the disk, if any file fails execution will continue. Any failed files will be reported by Upload::errors()

Parameters

$file
string
$file A field name to search the global file variable for
$overwrite
boolean
$overwrite Whether or not to overwrite the file if it already exists
$file_name
string
$file_name The name of the file to use instead of the uploaded file's name, null to use uploaded file's name
$rename_callback
callable
$rename_callback A callback to execute used to rename the file
public
# writeFiles( array $files, boolean $overwrite = true, array $file_names = null, callable $rename_callback = null )

Writes multiple files to the file system. Because of the nature of writing files to the disk, if any file fails execution will continue. Any failed files will be reported by Upload::errors()

Writes multiple files to the file system. Because of the nature of writing files to the disk, if any file fails execution will continue. Any failed files will be reported by Upload::errors()

Parameters

$files
array
$files An array of file field names to search the global file variable for
$overwrite
boolean
$overwrite Whether or not to overwrite the file if it already exists
$file_names
string
$file_name The name of the file to use instead of the uploaded file's name, null to use uploaded file's name
$rename_callback
callable
$rename_callback A callback to execute used to rename the file
private boolean
# write( array $file, string $key = null, string $index = null, boolean $overwrite = true, string $file_name = null, callable $rename_callback = null )

Writes a file to the file system from the given set files

Writes a file to the file system from the given set files

Parameters

$file
array
$file An array of file information
$key
string
$key The index in the $file array to fetch from
$index
string
$index The index in the $file array to fetch from (if a multi-upload file array)
$overwrite
boolean
$overwrite Whether or not to overwrite the file if it already exists
$file_name
string
$file_name The name of the file to use instead of the uploaded file's name, null to use uploaded file's name
$rename_callback
callable
$rename_callback A callback to execute used to rename the file

Returns

boolean
True if the file was written, false otherwise
public array
# getUploadData( )

Fetches the upload data

Fetches the upload data

Returns

array
An array of upload data for each of the uploaded files including: -orig_name The original name of the uploaded file -file_name The new file name -file_path The path where the file was written -full_path The full path to the file that was written -file_size The size of the file that was written (in bytes)
public
# createUploadPath( string $path, integer $permissions = 0755 )

Recursively creates the upload path if it does not already exists. Also sets permissions to the given set when the directory is created

Recursively creates the upload path if it does not already exists. Also sets permissions to the given set when the directory is created

Parameters

$path
string
$path The directory path to create
$permissions
integer
$permissions The permission value in octets
public array
# errors( )

Returns all errors set

Returns all errors set

Returns

array
An array of errors set in Input
public string
# appendCount( string $file_name )

Returns a suggested file name with a number appended at the end so that it is unique in the upload path

Returns a suggested file name with a number appended at the end so that it is unique in the upload path

Parameters

$file_name
string
$file_name The name of the file to append a count to

Returns

string
The suggested file name
public string
# md5( mixed $file_name )

Returns a suggested file name that uses an MD5 hash of the existing file name while preserving the file extension. For example my_file.txt becomes 3715ac9af3d0d8cb0970e08494034357.txt, that is md5(my_file.txt) with .txt appended.

Returns a suggested file name that uses an MD5 hash of the existing file name while preserving the file extension. For example my_file.txt becomes 3715ac9af3d0d8cb0970e08494034357.txt, that is md5(my_file.txt) with .txt appended.

Returns

string
The suggested file name

Magic methods summary

Properties summary

private array $allowed_mime_types
#

An array of allowed MIME types

An array of allowed MIME types

private integer $max_file_size
#

The maximum file size allowed, 0 for unlimited

The maximum file size allowed, 0 for unlimited

private string $upload_path
#

The full path to the upload directory, where files should be written

The full path to the upload directory, where files should be written

private array $files
#

An array of files from the global FILES variable

An array of files from the global FILES variable

private array $errors
#

An array of errors to be set

An array of errors to be set

private array $data
#

An array of data about the upload

An array of data about the upload

private boolean $uploaded_files
#

True if the files given have been uploaded, false if they were created instead

True if the files given have been uploaded, false if they were created instead

Blesta API documentation generated by ApiGen 2.8.0