I want to upload an image using Efineuploader plugin for Yii, and i don't know how to call the uploadStoredFiles
method to upload an image once the user has viewed the preview thumbnail (via ajax on onComplete
) . I don't know if there's a way to call it from the widget or if I can use a external button to use it.
This is my code:
$this->widget('ext.EFineUploader.EFineUploader',
array(
'id'=>'FineUploader',
'config'=>array(
'autoUpload'=>false,
'request'=>array(
'endpoint'=>$this->createAbsoluteUrl('articulo/upload'),//'/files/upload',// OR $this->createUrl('files/upload'),
'params'=>array('YII_CSRF_TOKEN'=>Yii::app()->request->csrfToken),
),
'retry'=>array('enableAuto'=>true,'preventRetryResponseProperty'=>true),
'chunking'=>array('enable'=>true,'partSize'=>100),//bytes
'template'=>'<div class="qq-uploader span4" style="float:left;"><div class="qq-upload-button btn">Seleccionar</div><div class="qq-upload-button btn">Enviar</div><br/><br/><ul class="qq-upload-list"></ul><br/></div>',
'callbacks'=>array(
'onComplete'=>"js:function(id, name, response)
{
$.post(
'".Yii::app()->baseUrl . "/articulo/mostrarImagen',
{'nombre': response[\"filename\"]},
function(respuesta)
{
$('#imagenSubida').html(respuesta);
}
)
}",
//'onError'=>"js:function(id, name, errorReason){ }",
),
'validation'=>array(
'allowedExtensions'=>array('jpg','jpeg'),
'sizeLimit'=>5*1024 * 1024,//maximum file size in bytes
'minSizeLimit'=>100*1024,// minimum file size in bytes
),
)
));
Thanks in advance
make sure the form has enctype='multipart/form-data' attribute set
in the endpoint parameter you put
'endpoint'=>$this->createAbsoluteUrl('articulo/upload'),
so go to the articulo controller, create a actionUpload function and have the function handle the upload
use the $_FILES variable to get the information about the uploaded file and you can try with the function move_uploaded_file or copy to move it to a permanent folder. if you're using chrome, in the developer tools find the network panel, that way you can debug the ajax requests and answers