HiboxUploadController.php 2.74 KB
<?php 
Yii::import("ext.xupload.models.UploadFileForm");
Yii::import("ext.xupload.models.UploadImageForm");

class HiboxUploadController extends Controller
{
     public function actions()
    {
        return array(
                        // FLASH  上传
                        'upload'=>array(
                                           'class' => 'application.extensions.swfupload.SWFUploadAction',
                                           'path' => realpath(Yii::app()->getBasePath()."/../upload/common"),
                                       ),
                        // 文件类型上传
                        'uploadFile' => array(
                                                 'class' => 'ext.xupload.actions.UploadFileAction',
                                                 'subfolderVar' => 'file',
                                                 'path' => realpath(Yii::app()->getBasePath()."/../upload/files"),
                                             ),
                        // 图片类型上传
                        'uploadImage' => array(
                                                  'class' => 'ext.xupload.actions.UploadImageAction',
                                                  'subfolderVar' => 'image',
                                                  'path' => realpath(Yii::app()->getBasePath()."/../upload/images"),
                                              ),
                    );
    }
    
    /**
     * 图片上传
     */
    public function actionIndexUploadImage()
    {
        $model = new UploadImageForm;
        
        $this->render('image', array(
                                        'model' => $model,
                                        'r' => null,
                     ));
    }

    /**
     * 文件上传
     */
    public function actionIndexUploadFile()
    {
        $model = new UploadFileForm;
        
        $this->render('file', array(
                                       'model' => $model,
                                       'r' => null,
                     ));
    }

    /**
     * 多文件上传
     */
    public function actionIndexUploadMultiple()
    {
        $model = new UploadFileForm;
        
        $this->render('multiple', array(
                                           'model' => $model,
                                           'r' => null,
                     ));
    }
    
    /**
     * 异常错误处理
     */
    public function actionError()
    {
        if ($error = Yii::app()->errorHandler->error)
        {
            if (Yii::app()->request->isAjaxRequest)
            {
                echo $error['message'];
            }
            else
            {
                $this->render('error', $error);
            }
        }
    }
}
?>