HTTP错误:用于yii框架的500 uploadify-widget

时间:2012-03-19 21:58:57

标签: yii uploadify

我正在使用https://github.com/yiiext/uploadify-widget,我花了很多时间尝试解决错误HTTP错误:500,我没有想法如何调试

这里是查看protected/views/admin/_form_photo.php

<?php
$this->widget('ext.uploadify.EUploadifyWidget', array(
    // you can either use it for model attribute
    'model' => new UploadifyFile,
    'attribute' => 'file1',
    // or just for input field
    'name' => 'UploadifyFile_file1',
    // the name of the POST parameter where save session id
    'sessionParam' => 'PHP_SESSION_ID',
    // extension [options](http://www.uploadify.com/documentation/)
    'options' => array(
        'fileExt' => '*.jpg;*.png;*.gif',
        'script' => $this->createUrl('SwfUpload'),
        'debug' => true,
        'auto' => false,
        'multi' => true,
        'buttonText' => 'Upload Images',
        'onError' => 'js:function (event,ID,fileObj,errorObj) { alert(errorObj.type + \' Error: \' + errorObj.info); }'
    )
));
?>

我有模型protected/models/UploadifyFile.php

<?php

class UploadifyFile extends CFormModel
{
    public $uploadifyFile;

    public function rules()
    {
        return array(
            array(
                'uploadifyFile',
                'file',
                'maxSize' => 1024 * 1024 * 1024,
                'types' => 'jpg, png, gif, txt'
            )
        );
    }
}

?>

我有行动protected/controllers/SwfUploadAction.php

<?php
    class SwfUploadAction extends CAction
    {
        public $folder;

        public function run()
        {
            $folder = $this->folder;

            if ($folder === false) {
                throw new CException(Yii::t(__CLASS__, "Folder does not exists.", array()));
            }
            if (isset($_FILES['UploadifyFile']) === true) {
                $model                = new UploadifyFile;
                $model->attributes    = array(
                    'uploadifyFile' => ''
                );
                $model->uploadifyFile = CUploadedFile::getInstance($model, 'uploadifyFile');
                if ($model->validate() === false) {
                    throw new CException(Yii::t(__CLASS__, "Invalid file.", array()));
                }
                if (!$model->uploadifyFile->saveAs($folder . '/' . $model->uploadifyFile->getName())) {
                    throw new CException(Yii::t(__CLASS__, "Upload error.", array()));
                } else {
                    die("Upload success");
                }
            } else {
                throw new CException(Yii::t(__CLASS__, "File not sent.", array()));
            }
            throw new CException(Yii::t(__CLASS__, 'Unknown error.', array()));
        }
    }

    ?>

来自控制器protected/controllers/AdminController.php的操作:

function actions()
{
    return array(
        'SwfUpload' => array(
            'class' => 'application.controllers.SwfUploadAction',
            'folder' => 'images'
        )
    );
}

我读过这篇文章,可能是flash验证问题,我必须使用forgerySession http://code.google.com/p/yiiext/source/browse/trunk/app/extensions/yiiext/filters/forgerySession/,我不知道如何配置它,提前大谢!!!!

1 个答案:

答案 0 :(得分:0)

解决此问题的最简单方法是允许未经授权的访问操作。也就是说,如果您在应用程序中进行身份验证检查,则对于特定的上载操作,返回true表示未经授权。

对于提出更具体的答案,我需要知道您是如何在应用程序中进行身份验证的。