在 PHP Codeigniter 中上传 HTTP 302 错误和 IO 错误

Uploadify HTTP 302 error and IO error in PHP Codeigniter

我尝试将我的 Codeigniter 网站与 uploadify 集成。它在 Chrome 甚至 IE 中工作正常,但是当我在 Mozilla firefox 中运行我的网站时出现 HTTP 302 错误。有时它也显示 "IO Error",我读了这篇文章:302 and IO uploadify error,但仍然不知道我必须做什么。也许更多 detail/clear 指南会有所帮助。

这是我在视图中的上传配置:

$('#shopfile').uploadify({
            'debug':false,
            'auto':true,
            'swf': '<?= base_url(); ?>file/lib/uploadify/uploadify.swf',
            'uploader': '<?= base_url(); ?>my_shop/upload_shopheader',
            'cancelImg': '<?= base_url(); ?>file/lib/uploadify/uploadify-cancel.png',
            'fileTypeExts':'*.jpg;*.jpeg;*.png;',
            'fileTypeDesc':'Image Files (.jpg,.jpeg,.png)',
            'fileSizeLimit':'2MB',
            'fileObjName':'shopfile',
            'buttonText':'Select File',
            'multi':false,
            'removeCompleted':false,
            'onUploadError' : function(file, errorCode, errorMsg, errorString) {
                alert('The file ' + file.name + ' could not be uploaded: ' + errorString);
                $( ".uploadMessageStr" ).html('<div class="alert alert-danger">The file ' + file.name + ' could not be uploaded: ' + errorString + '</div>');
            },
            'onUploadSuccess' : function(file, data, response){
                //some statement..
            }
        });

这是我的控制器/上传器功能代码:

public function upload_shopheader(){
    if (empty($_FILES['shopfile']['name'])) redirect('my_shop/profile');

    $config = $this->avatarUploadConfig();
    $this->upload->initialize($config);
    $data = array();

    if (!$this->upload->do_upload('shopfile')) { 
        //if upload failed...
        $upload_error = $this->upload->display_errors();
        $data['message'] = "<div class='alert alert-danger'>Upload Failed. ".$upload_error."</div>";
    } 
    else { 
        //if upload success...
    }

    echo json_encode($data);
}

先谢谢了。

通过 uploadify 手动添加会话 ID 已解决。

将此添加到视图中的上传配置:

'formData' : {'SESSION_ID' : '<?= $this->session->userdata('session_id'); ?>'},

并在控制器函数的开头添加此代码:

//check session..
    $sess_id = $this->input->post('SESSION_ID');
    if(!isset($sess_id)){
        redirect('to_some/page');
    }
    else{
        $this->session->set_userdata(array('session_id' => $sess_id));
    }