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

时间:2015-01-08 17:09:57

标签: php codeigniter uploadify

我尝试将我的Codeigniter网络与uploadify集成。它在Chrome甚至IE中工作得很好,但是当我在Mozilla Firefox中运行我的网页时出现HTTP 302错误。有时它也显示“IO错误”,我读了这篇文章:302 and IO uploadify error,但仍然不知道我必须做什么。也许更详细/清晰的指南会有所帮助。

这是我在视图中的uploadify配置:

$('#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);
}

先谢谢。

1 个答案:

答案 0 :(得分:2)

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

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

'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));
    }