0

CodeIgniter 2.1.4 では、ajax と File Uploading Class を使用してファイルをアップロードしようとしています。コントローラーに次のような構成があります。

public function __construct()
{
    parent::__construct();
    $this->load->helper(array('form', 'url'));
}

そして、コントローラーでの私のアップロード機能は次のとおりです。

public function upload_file()
{

    $config['upload_path'] = 'upload/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '100';
    $config['max_width']  = '1024';
    $config['max_height']  = '768';

    $this->load->library('upload', $config);
    if (!$this->upload->do_upload())
    {
        $error = array('error' => $this->upload->display_errors());
        $result['success'] = 1;
        $result['message'] = $error;
    }
    else
    {
        $result['success'] = 0;
        $result['message'] = "Successful Upload";
    }

    die(json_encode($result));

}

しかし、エラーは次のように出てきます:

Array

配列からエラー メッセージを取得するにはどうすればよいですか?

4

2 に答える 2

1

この行を変更して試してください:

$result['message'] = $error['error'];
于 2013-07-26T09:38:52.337 に答える
0

エラーが発生した場合、結果は配列になります。die 関数で json エンコードを使用しました。

die 関数でエンコードしないでください。

echo json_encode($result);
die();
于 2013-07-26T09:44:34.367 に答える