...overview of the extension... Using this extension you can upload multiple files at a single time which can also contain multiple extensions.
Requirements ¶
...requirements of using this extension (e.g. Yii 1.1 or above)...
Usage ¶
...how to use this extension... 1.Extract this extension into your protected/extensions folder.. 2.In Your Main.php Copy This Code...
'import'=>array(
'application.extensions.EAjaxUpload.*',
),
3.In your View page..
<?php
$this->widget('ext.EAjaxUpload.EAjaxUpload',
array(
'id'=>'uploadFile',
'config'=>array(
'action'=>Yii::app()->createUrl('site/upload'),
'allowedExtensions'=>array("jpg","jpeg","gif","exe","mov","mp4","txt","doc","pdf","xls","3gp","php","ini","avi","rar","zip","png"),//array("jpg","jpeg","gif","exe","mov" and etc...
'sizeLimit'=>1000*1024*1024,// maximum file size in bytes
'minSizeLimit'=>1*1024,
'auto'=>true,
'multiple' => true,
'onComplete'=>"js:function(id, fileName, responseJSON){ alert(fileName); }",
'messages'=>array(
'typeError'=>"{file} has invalid extension. Only {extensions} are allowed.",
'sizeError'=>"{file} is too large, maximum file size is {sizeLimit}.",
'minSizeError'=>"{file} is too small, minimum file size is {minSizeLimit}.",
'emptyError'=>"{file} is empty, please select files again without it.",
'onLeave'=>"The files are being uploaded, if you leave now the upload will be cancelled."
),
'showMessage'=>"js:function(message){ alert(message); }"
)
));
?>
4.In Your Controller
public function actionUpload()
{
Yii::import("ext.EAjaxUpload.qqFileUploader");
$folder=Yii::getPathOfAlias('webroot').'/upload/';// folder for uploaded files
$allowedExtensions = array("jpg","jpeg","gif","exe","mov","mp4");//array("jpg","jpeg","gif","exe","mov" and etc...
$sizeLimit = 100 * 1024 * 1024;// maximum file size in bytes
$uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
$result = $uploader->handleUpload($folder);
$return = htmlspecialchars(json_encode($result), ENT_NOQUOTES);
$fileSize=filesize($folder.$result['filename']);//GETTING FILE SIZE
$fileName=$result['filename'];//GETTING FILE NAME
//$img = CUploadedFile::getInstance($model,'image');
echo $return;// it's array
}
5.This will work like charm. 6.If u need to add or choose the size of ur upload and download just change in the view widget.
Enojy file uploading
Vague documentation
manoj20
Its not clear how variables set in the widget are being passed onto the controller and you assume people know where to "if ($postSize > $this->sizeLimit || $uploadSize > $this->sizeLimit) to if ($postSize < $this->sizeLimit || $uploadSize < $this->sizeLimit) "
Reply:
Hello The Zohan ,
Its present in qqFileUploader.php in line 87.
post_max_size & upload_max_size error
hi,
it doesn't matter if you set post_max_size and upload_max_size into php.ini unless values ARE IDENTICAL with the ones from this extensions.
Wrong logic
Hi manoj,
I believe the zohan has a valid point.
In qqFileUploader.php in line 87 you have
if ($postSize > $this->sizeLimit || $uploadSize > $this->sizeLimit){ $size = max(1, $this->sizeLimit / 1024 / 1024) . 'M'; die("{'error':'increase post_max_size and upload_max_filesize to $size'}"); }
which mean: if the ini files max is greater that what we allow, tell the user to increase it and die.
The correct login IMHO is like the zohan suggested
if ($postSize < $this->sizeLimit || $uploadSize < $this->sizeLimit){ $size = max(1, $this->sizeLimit / 1024 / 1024) . 'M'; die("{'error':'increase post_max_size and upload_max_filesize to $size'}"); }
Thank you for a great extension.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.