I had a look through the extensions to find something that would be suitable but I did not find anything. Basically what I’m after a multi-photo upload tool that has the following:
Displays an upload progress bar for each photo
Checks for MIME type to ensure it is a valid photo
(Optionally) creates a thumbnail of the photo
I would have used a flash based upload tool like ‘Uploadify’ but I read that it changes the MIME type to octet or something? Plus it’s Flash and some people might not have/use Flash.
for image validation (i prefered to use my own function instead of a validator, that is up to you)
// this one i use to create a unique file name
public static function createPictureName($name){
return md5($name . time()).(strtolower(strrchr($name, '.')));
}
// this to validate picture
// obviously the constant names are declared within the class
// you include these functions!!!
// example of use:
// $result = Picture::validateUploadedPicture($picture_file,1480,1240,240,180,array('image/jpeg','image/gif','image/png'));
public static function validateUploadedPicture( CUploadedFile $file, $maxWidth, $maxHeight, $minWidth, $minHeight, $mimeTypes ){
$info = @getimagesize( $file->getTempName() );
// remove unnecessary values from $info and make it more readable
$info = array(
'width' => $info[0],
'height' => $info[1],
'mime' => $info['mime'],
);
if ($info['width'] < $minWidth) {
return self::MIN_WIDTH_ERROR;
}
if ($info['width'] > $maxWidth) {
return self::MAX_WIDTH_ERROR;
}
if ($info['height'] < $minHeight) {
return self::MIN_HEIGHT_ERROR;
}
if ($info['height'] > $maxHeight) {
return self::MAX_HEIGHT_ERROR;
}
$mimeTypes = is_scalar($mimeTypes) ? array($mimeTypes) : $mimeTypes;
if (!in_array($info['mime'], $mimeTypes)) {
return self::MIME_TYPE_ERROR;
}
return self::PICTURE_VALID;
}
I have successfully created galleries with this approach for couple of projects.
As previously said, I tried before File Validators and I rather used my own approach. At the end of the day G is what makes you comfortable to work with. I decided to use Yii because wasnt that strict at all with procedures…
I never had a problem with SWFUpload G and I have successfully created picture galleries and also document uploads (pdf and msword). If you have any problem let me know, here a set of MIME for doc validation used in another project:
private function validateMimeType(CUploadedFile $doc){
$mime = trim(CFileHelper::getMimeType($doc->getTempName()));
switch ($mime){
case 'application/msword':
case 'application/doc':
case 'application/text':
case 'application/vnd.msword':
case 'application/vnd.ms-word':
case 'application/winword':
case 'application/word':
case 'application/x-msw6':
case 'application/x-msword':
case 'application/vnd.ms-office':
case 'zz-application/zz-winassoc-doc':
case 'application/pdf':
return true;
}
return false;
}
I am having a couple of issues with SWFUpload. I downloaded the one from the extension library, as I noticed yours was in Spanish
When I upload a file that is too big I don’t get any error message, nothing happens.
I can upload multiple files but how do I make it upload multiple files in the same style as here: http://demo.swfupload.org/v220/multiinstancedemo/index.php, i.e. the files appear in a list and they have got a cancel button on each. Currently I only have one file “row” in my list and it doesn’t have a cancel button.
jacmoe - have you used this extension? I cannot figure out how to use it - is the ‘url’ parameter meant to point to the controller action that will handle the upload? If so, can you just use the normal CUploadedFile method to upload the file?