Hey, guys,
Thanks for trying fancyupload. I’ve released a new version 1.1, please, take a look at extensions for downloading the latest file (there are a few improvements and working code samples)
I’m sorry don’t speak German, but I’ll try to help you.
Could you please perform the following test in your application?
1 - Create a folder called tmp under your protected folder, which will store the uploaded files and give it write permission /full access (in Linux chmod 777, in Windows Everyone Full Control). So we have now /protected/tmp to store files.
2 - Put the following code in your protected/controllers/SiteController.php:
//this is to render the view fancy.php, where we will call the widget sfancyupload
public function actionFancy(){
$this->render('fancy');
}
//this is to manage the uploaded files
public function actionUploadedFiles(){
$file = CUploadedFile::getInstanceByName("Filedata");
$return = array(
'status' => '1',
'name' => $file->getName()
);
/**
* ATENTION: this is for demonstration purposes only.
* In a real world application, you'd better validate
* the files according to your needs
*/
switch(CFileHelper::getMimeType($file->getTempName())){
case 'application/zip':
break;
case 'image/jpeg':
$info = @getimagesize($file->getTempName());
if ($info) {
$return['width'] = $info[0];
$return['height'] = $info[1];
$return['mime'] = $info['mime'];
}
break;
default:
$return = array(
'status' => '0',
'error' => 'Filetype not allowed'
);
}
//here we'll use the folder tmp to store the uploaded files
$file->saveAs(Yii::app()->getBasePath().'/tmp/'.$file->getName());
//this is to return, in case of images, the width and height to the view
echo json_encode($return);
}
3 - Create a file under protected/views/site and name it fancy.php. Put the following code inside:
<?php
//$this->layout = ‘fancy’;
$statusBoxId = ‘fancy-status’;
$clearButton = ‘fancy-clear’;
$uploadButton = ‘fancy-upload’;
$this->widget(‘application.extensions.fancyupload.SFancyUpload’,
array(
'name'=>'form-fancy',
'statusBoxId'=>$statusBoxId,
'clearButton'=>$clearButton,
'uploadButton'=>$uploadButton,
'clearButtonLabel'=>'Limpar Lista',
'uploadButtonLabel'=>'Enviar',
'targetLabel'=>'Selecionar Arquivos',
'options'=> array(
'verbose'=>true,
'url'=>$this->createUrl('site/UploadedFiles'),
'multiple'=>true,
'target'=>'fancy-browse',
'typeFilter'=>array('Imagens (jpg, jpeg, gif, png)'=>'*.jpg; *.jpeg; *.gif; *.png'),//,'Arquivos Compactados'=>'*.zip; *.rar'),
//'instantStart'=>true,
//'data'=>array('teste'=>$uploadButton),
),
'callbacks' => array(
//'onComplete' => 'function(){alert("Complete");}',
//'onCancel' => 'function(evt,queueId,fileObj,data){alert("Cancelled");}',
'onLoad'=>"function() {
$('$statusBoxId').removeClass('hide');
$('fancy-fallback').destroy();
// We relay the interactions with the overlayed flash to the link
this.target.addEvents({
click: function() {
return false;
},
mouseenter: function() {
this.addClass('hover');
},
mouseleave: function() {
this.removeClass('hover');
this.blur();
},
mousedown: function() {
this.focus();
}
});
// Interactions for the 2 other buttons
$('$clearButton').addEvent('click', function() {
up.remove(); // remove all files
return false;
});
$('$uploadButton').addEvent('click', function() {
up.start(); // start upload
return false;
});
}",
'onFail'=> 'function(error) {
switch (error) {
case "hidden": // works after enabling the movie and clicking refresh
alert("Para habilitar o sistema de upload, desbloqueie no seu browser e atualize.");
break;
case "blocked": // This no *full* fail, it works after the user clicks the button
alert("Para habilitar o sistema de upload, habilite o filme flash bloqueado");
break;
case "empty": // Oh oh, wrong path
alert("O sistema de upload parece estar faltando, por favor, tente mais tarde");
break;
case "flash": // no flash 9+ <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />
alert("Precisa ter o plugin do Adobe Flash 9 ou superior para usar o upload")
}
}',
'onFileSuccess'=> "function(file, response) {
var json = new Hash(JSON.decode(response, true) || {});
if (json.get('status') == '1') {
file.element.addClass('file-success');
//file.element.set({style: 'background-image:url(/pirata/images/site/bt_favstar.gif)'});
file.info.set('html', '<strong>Arquivo enviado:</strong> (' + json.get('width') + ' x ' + json.get('height') + 'px, <em>' + json.get('mime') + '</em>)');
} else {
file.element.addClass('file-failed');
file.info.set('html', '<strong>Erro no envio:</strong> (' + (json.get('error') ? (json.get('error') + ' #' + json.get('code')) : response));
}
}",
'onSelectFail'=> "function(files) {
files.each(function(file) {
new Element('li', {
'class': 'validation-error',
html: file.validationErrorMessage || file.validationError,
title: MooTools.lang.get('FancyUpload', 'removeTitle'),
events: {
click: function() {
this.destroy();
}
}
}).inject(this.list, 'top');
}, this);
}",
/*'onFileComplete'=> "function(file) {
up.fileRemove(file);
}",*/
'onComplete'=>"function() {
// $('fancy-status').setStyle('display','none');
//up.remove();
el = $$('.file-success');
for (i=0; i<el.length; i++){
el[i].destroy();
}
}",
//‘onBeforeStart’=>"function() {
//var hash = {};
//document.cookie.split(/;\s*/).each(function(cookie) {
//cookie = cookie.split(’=’);
//if (cookie.length == 2) {
//hash[decodeURIComponent(cookie[0])] = decodeURIComponent(cookie[1]);
//}
//});
//
//up.setOptions({
//data: {cookieName: hash[‘myfield’], myfield: $(‘myfield’).get(‘value’)}
//});
//}",
)
));
?>
4 - Save all and access the url http://yourapplication/site/fancy or http://yourapplication/index.php?r=site/fancy
You should see two bars and three links: to select files, upload them and clear the queue
I’ve just tested this and the code above worked for me.
Please let me know if it works for you now.
Regards!!!