evoself 2012-07-22 19:13:03 3638次浏览 4条回复 0 0 0

这玩意折腾了很久,可能是自己水平太菜了,只好来麻烦坛子里的兄弟了 我是这样做的,在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 真不知道怎么搞的,有谁能帮我看看先谢了

  • 回复于 2012-07-23 08:59 举报

    可以参考一下他的demo:
    http://code.google.com/p/swfupload/
    最好是把错误的截图发一下,或者是把源代码以附件的形式发布一下。

  • 回复于 2012-07-23 09:14 举报

    截图没内容,就是Error 500,Undefined index: Filedata
    我就是找教程上弄的怎么就不对呢

  • 回复于 2012-07-23 10:14 举报

    控制器明显写得有问题。

    actionUploads(){
    if ($_POST){
        //
    }
        $this->render('');
    }
    

    至少应该是这样写吧。

  • 回复于 2012-07-23 19:35 举报

    官方的demo:http://demo.swfupload.org/v220/applicationdemo/index.php
    这个效果怎么写呢

您需要登录后才可以回复。登录 | 立即注册