swfupload使用 [ 新手入门 ]
这玩意折腾了很久,可能是自己水平太菜了,只好来麻烦坛子里的兄弟了 我是这样做的,在controller里新建一个upload的控制器,然后输入教程里的代码
<?php
class UploadsController extends Controller
{
public $defaultAction='uploads';
public function accessRules()
{
return array(
array( 'allow',
// allow all users to perform 'index' and 'view' actions ),
'actions'=>array('index','view','updateajax','uploads'),
'users'=>array('*'),
),
);
}
public function actionUploads()
{
$year=date('Y');
$month=date('m');
$path='upload/'.$year.'/'.$month.'/';
//如果目录不存在就创建目录
if(!file_exists('upload/'.$year.'/'))
{
mkdir('upload/'.$year.'/','0777');
}
if(!file_exists($path))
{
mkdir($path,'0777');
}
$filedata=$_FILES['Filedata'];
@move_uploaded_file($filedata['tmp_name'],$path.uniqid().'.gif');
}
}
视图里
<?php
$this->widget('application.extensions.swfupload.CSwfUpload', array(
'jsHandlerUrl'=>Yii::app()->theme->baseUrl.'/js/handlers.js', //Relative path
'postParams'=>array(),
'config'=>array(
'use_query_string'=>true,
'upload_url'=>$this->createUrl('/uploads'), //Use $this->createUrl method or define yourself
'file_size_limit'=>'2 MB',
'file_types'=>'*.jpg;*.png;*.gif',
'file_types_description'=>'Image Files',
'file_upload_limit'=>0,
'file_queue_error_handler'=>'js:fileQueueError',
'file_dialog_complete_handler'=>'js:fileDialogComplete',
'upload_progress_handler'=>'js:uploadProgress',
'upload_error_handler'=>'js:uploadError',
'upload_success_handler'=>'js:uploadSuccess',
'upload_complete_handler'=>'js:uploadComplete',
'custom_settings'=>array('upload_target'=>'divFileProgressContainer'),
'button_placeholder_id'=>'swfupload',
'button_width'=>170,
'button_height'=>20,
'button_text'=>'<span class="button">'.Yii::t('messageFile', 'ButtonLabel').' (Max 2 MB)</span>',
'button_text_style'=>'.button { font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; font-size: 11pt; text-align: center; }',
'button_text_top_padding'=>0,
'button_text_left_padding'=>0,
'button_window_mode'=>'js:SWFUpload.WINDOW_MODE.TRANSPARENT',
'button_cursor'=>'js:SWFUpload.CURSOR.HAND',
),
)
);
?>
<?php echo CHtml::beginForm(); ?>
<div class="form">
<div class="row">
<div id="divFileProgressContainer"></div>
<div class="swfupload"><span id="swfupload"></span></div>
</div>
</div>
<?php echo CHtml::endForm(); ?>
jsHandlerUrl
是在themes下面的,结果总是Error 500,Undefined index: Filedata
真不知道怎么搞的,有谁能帮我看看先谢了
共 4 条回复
evoself
注册时间:2011-03-01
最后登录:2013-08-02
在线时长:0小时0分
最后登录:2013-08-02
在线时长:0小时0分
- 粉丝1
- 金钱420
- 威望0
- 积分420