library yii-uploaded-file
A wrapper for CUploadedFile class of PHP Yii framework.
yanli0303/yii-uploaded-file
A wrapper for CUploadedFile class of PHP Yii framework.
- Wednesday, May 20, 2015
- by yanli0303
- Repository
- 1 Watchers
- 0 Stars
- 3 Installations
- PHP
- 0 Dependents
- 0 Suggesters
- 0 Forks
- 0 Open issues
- 2 Versions
- 0 % Grown
Yii-UploadedFile
By Yan Li, (*1)
, (*2)
A wrapper for CUploadedFile class of PHP Yii framework.
It adds following help methods to CUploadedFile class:, (*3)
- isExtensionInList($extensions)
- isMimeTypeInList($mimeTypes)
- isImageTypeInList($imageTypes)
- validateImageDimensions($maxWidth, $maxHeight, $minWidth, $minHeight)
- validate($maxFileBytes, $allowedExtensions, $allowedMimeTypes)
- validateImage($maxFileBytes, $allowedExtensions, $allowedImageTypes, $maxWidth = null, $maxHeight = null, $minWidth = null, $minHeight = null)
- saveImage($saveAs, $pngToJpg = false)
Usage
$maxBytes = 4194304; //4 * 1024 * 1024 = 4MB
$allowedExtensions = array('.png', '.jpg', '.jpeg');
$allowedTypes = array(IMAGETYPE_JPEG, IMAGETYPE_PNG);
$uploaded = new UploadedFile('file');
$error = $uploaded->validateImage($maxBytes, $allowedExtensions, $allowedTypes);
if (is_string($error)) {
throw new Exception($error);
}
$saveAs = '/webroot/uploads/images/'.basename($uploaded->file->getName());
$saved = $uploaded->saveImage($saveAs, false);
if (empty($saved)) {
throw new Exception('Sorry, we couldn\'t upload the image.');
}
// do sth with saved image: $saved
dev-master
9999999-dev
A wrapper for CUploadedFile class of PHP Yii framework.
Sources
Download
MIT
The Requires
The Development Requires
by
Yan Li
v0.1
0.1.0.0
A wrapper for CUploadedFile class of PHP Yii framework.
Sources
Download
MIT
The Requires
The Development Requires
by
Yan Li