API - XOOPS 2.5.11 Beta 2
By monxoops.fr
XoopsMediaUploader Class Reference

Public Member Functions

 __construct ($uploadDir, $allowedMimeTypes, $maxFileSize=0, $maxWidth=null, $maxHeight=null, $randomFilename=false)
 
 return_bytes ($size_str)
 
 countMedia ($media_name)
 
 fetchMedia ($media_name, $index=null)
 
 setTargetFileName ($value)
 
 setPrefix ($value)
 
 getMediaName ()
 
 getMediaType ()
 
 getMediaSize ()
 
 getMediaTmpName ()
 
 getSavedFileName ()
 
 getSavedDestination ()
 
 upload ($chmod=0644)
 
 _copyFile ($chmod)
 
 checkMaxFileSize ()
 
 checkMaxWidth ()
 
 checkMaxHeight ()
 
 checkMimeType ()
 
 checkImageType ()
 
 sanitizeMultipleExtensions ()
 
 setErrors ($error)
 
getErrors ($ashtml=true)
 

Data Fields

 $allowUnknownTypes = false
 
 $mediaName
 
 $mediaType
 
 $mediaSize
 
 $mediaTmpName
 
 $mediaError
 
 $mediaRealType = ''
 
 $uploadDir = ''
 
 $allowedMimeTypes = array()
 
 $deniedMimeTypes
 
 $maxFileSize = 0
 
 $maxWidth
 
 $maxHeight
 
 $targetFileName
 
 $prefix
 
 $errors = array()
 
 $savedDestination
 
 $savedFileName
 
 $extensionToMime = array()
 
 $checkImageType = true
 
 $extensionsToBeSanitized
 
 $imageExtensions
 
 $randomFilename = false
 

Protected Member Functions

 arrayPushIfPositive ($set, $value)
 

Detailed Description

Upload Media files

Example of usage (single file): include_once 'uploader.php'; $allowed_mimetypes = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png'); $maxfilesize = 50000; $maxfilewidth = 120; $maxfileheight = 120; $randomFilename = true; $uploader = new XoopsMediaUploader('/home/xoops/uploads', $allowed_mimetypes, $maxfilesize, $maxfilewidth, $maxfileheight, $randomFilename); if ($uploader->fetchMedia('single_file_name')) { if (!$uploader->upload()) { echo $uploader->getErrors(); } else { echo '

File uploaded successfully!

' echo 'Saved as: ' . $uploader->getSavedFileName() . '
'; echo 'Full path: ' . $uploader->getSavedDestination(); } } else { echo $uploader->getErrors(); }

Example of usage (multiple file): include_once 'uploader.php'; $allowed_mimetypes = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png'); $maxfilesize = 50000; $maxfilewidth = 120; $maxfileheight = 120; $randomFilename = true; $uploader = new XoopsMediaUploader('/home/xoops/uploads', $allowed_mimetypes, $maxfilesize, $maxfilewidth, $maxfileheight, $randomFilename); for ($i = 0; $i < $uploader->countMedia('multiple_file_name'); $i++) { if ($uploader->fetchMedia('multiple_file_name')) { if (!$uploader->upload()) { echo $uploader->getErrors(); } else { echo '

File uploaded successfully!

' echo 'Saved as: ' . $uploader->getSavedFileName() . '
'; echo 'Full path: ' . $uploader->getSavedDestination(); } } else { echo $uploader->getErrors(); } }

Constructor & Destructor Documentation

◆ __construct()

__construct (   $uploadDir,
  $allowedMimeTypes,
  $maxFileSize = 0,
  $maxWidth = null,
  $maxHeight = null,
  $randomFilename = false 
)

Constructor

Parameters
string$uploadDir
array$allowedMimeTypes
int$maxFileSize
int$maxWidth
int$maxHeight
bool$randomFilename
Here is the call graph for this function:

Member Function Documentation

◆ _copyFile()

_copyFile (   $chmod)

Copy the file to its destination

Parameters
$chmod
Returns
bool
Here is the call graph for this function:
Here is the caller graph for this function:

◆ arrayPushIfPositive()

arrayPushIfPositive (   $set,
  $value 
)
protected

Push value onto set. Used in max file size calculation to eliminate -1 (unlimited) ini values

Parameters
array$setarray of values
int$valuevalue to push
Returns
mixed
Here is the caller graph for this function:

◆ checkImageType()

checkImageType ( )

Check whether or not the uploaded image type is valid

Returns
bool
Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkMaxFileSize()

checkMaxFileSize ( )

Is the file the right size?

Returns
bool
Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkMaxHeight()

checkMaxHeight ( )

Is the picture the right height?

Returns
bool
Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkMaxWidth()

checkMaxWidth ( )

Is the picture the right width?

Returns
bool
Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkMimeType()

checkMimeType ( )

Check whether or not the uploaded file type is allowed

Returns
bool
Here is the call graph for this function:
Here is the caller graph for this function:

◆ countMedia()

countMedia (   $media_name)

Count the uploaded files (in case of miltiple upload)

Parameters
string$media_nameName of the file field
Returns
int|false
Here is the call graph for this function:

◆ fetchMedia()

fetchMedia (   $media_name,
  $index = null 
)

Fetch the uploaded file

Parameters
string$media_nameName of the file field
int$indexIndex of the file (if more than one uploaded under that name)
Returns
bool
Here is the call graph for this function:

◆ getErrors()

& getErrors (   $ashtml = true)

Get generated errors

Parameters
bool$ashtmlFormat using HTML?
Returns
array |string Array of array messages OR HTML string

◆ getMediaName()

getMediaName ( )

Get the uploaded filename

Returns
string

◆ getMediaSize()

getMediaSize ( )

Get the size of the uploaded file

Returns
int

◆ getMediaTmpName()

getMediaTmpName ( )

Get the temporary name that the uploaded file was stored under

Returns
string

◆ getMediaType()

getMediaType ( )

Get the type of the uploaded file

Returns
string

◆ getSavedDestination()

getSavedDestination ( )

Get the destination the file is saved to

Returns
string

◆ getSavedFileName()

getSavedFileName ( )

Get the saved filename

Returns
string

◆ return_bytes()

return_bytes (   $size_str)

converts memory/file sizes as defined in php.ini to bytes

Parameters
$size_str
Returns
int
Here is the caller graph for this function:

◆ sanitizeMultipleExtensions()

sanitizeMultipleExtensions ( )

Sanitize executable filename with multiple extensions

Here is the caller graph for this function:

◆ setErrors()

setErrors (   $error)

Add an error

Parameters
string$error
Here is the caller graph for this function:

◆ setPrefix()

setPrefix (   $value)

Set the prefix

Parameters
string$value

◆ setTargetFileName()

setTargetFileName (   $value)

Set the target filename

Parameters
string$value

◆ upload()

upload (   $chmod = 0644)

Check the file and copy it to the destination

Parameters
int$chmod
Returns
bool
Here is the call graph for this function:

Field Documentation

◆ $allowedMimeTypes

$allowedMimeTypes = array()

◆ $allowUnknownTypes

$allowUnknownTypes = false

Flag indicating if unrecognized mimetypes should be allowed (use with precaution ! may lead to security issues )

◆ $checkImageType

◆ $deniedMimeTypes

$deniedMimeTypes
Initial value:
= array(
'application/x-httpd-php')

◆ $errors

$errors = array()

◆ $extensionsToBeSanitized

$extensionsToBeSanitized
Initial value:
= array(
'php',
'phtml',
'phtm',
'php3',
'php4',
'cgi',
'pl',
'asp',
'php5',
'php7',
)

◆ $extensionToMime

$extensionToMime = array()

◆ $imageExtensions

$imageExtensions
Initial value:
= array(
1 => 'gif',
2 => 'jpg',
3 => 'png',
4 => 'swf',
5 => 'psd',
6 => 'bmp',
7 => 'tif',
8 => 'tif',
9 => 'jpc',
10 => 'jp2',
11 => 'jpx',
12 => 'jb2',
13 => 'swc',
14 => 'iff',
15 => 'wbmp',
16 => 'xbm')

◆ $maxFileSize

$maxFileSize = 0

◆ $maxHeight

$maxHeight

◆ $maxWidth

$maxWidth

◆ $mediaError

$mediaError

◆ $mediaName

$mediaName

◆ $mediaRealType

$mediaRealType = ''

◆ $mediaSize

$mediaSize

◆ $mediaTmpName

$mediaTmpName

◆ $mediaType

$mediaType

◆ $prefix

$prefix

◆ $randomFilename

$randomFilename = false

◆ $savedDestination

$savedDestination

◆ $savedFileName

$savedFileName

◆ $targetFileName

$targetFileName

◆ $uploadDir

$uploadDir = ''

The documentation for this class was generated from the following file: