2017-03-27 13 views
1

BlueimpのjQuery Fie Uploadによって返されたJSONレスポンスに別の値を追加したいので、他の値がどこに追加されているのかわかりません。JSONレスポンスへのjQueryファイルアップロードの追加

私は

protected function get_orig_name($name){ 
     $orig_name = $name; 
     return $orig_name; 
} 

ファイルの元の名前を返す関数を...持っていると私はUploadHandler.phpからのJSON応答で返された値を追加したいと思いますが、私はワークアウト/どのようにすることはできません他の値が配列に追加されます。

私はまだOOP PHPに多くの経験がありません。

これは私がJSONレスポンスを作成すると思うのコードのsecionです...

public function generate_response($content, $print_response = true) { 
    $this->response = $content; 
    if ($print_response) { 
     $json = json_encode($content); 
     $redirect = stripslashes($this->get_post_param('redirect')); 
     if ($redirect && preg_match($this->options['redirect_allow_target'], $redirect)) { 
      $this->header('Location: '.sprintf($redirect, rawurlencode($json))); 
      return; 
     } 
     $this->head(); 
     if ($this->get_server_var('HTTP_CONTENT_RANGE')) { 
      $files = isset($content[$this->options['param_name']]) ? 
       $content[$this->options['param_name']] : null; 
      if ($files && is_array($files) && is_object($files[0]) && $files[0]->size) { 
       $this->header('Range: 0-'.(
        $this->fix_integer_overflow((int)$files[0]->size) - 1 
       )); 
      } 
     } 
     $this->body($json); 
    } 
    return $content; 
} 

public function get_response() { 
    return $this->response; 
} 

public function head() { 
    $this->header('Pragma: no-cache'); 
    $this->header('Cache-Control: no-store, no-cache, must-revalidate'); 
    $this->header('Content-Disposition: inline; filename="files.json"'); 
    // Prevent Internet Explorer from MIME-sniffing the content-type: 
    $this->header('X-Content-Type-Options: nosniff'); 
    if ($this->options['access_control_allow_origin']) { 
     $this->send_access_control_headers(); 
    } 
    $this->send_content_type_header(); 
} 

public function get($print_response = true) { 
    if ($print_response && $this->get_query_param('download')) { 
     return $this->download(); 
    } 
    $file_name = $this->get_file_name_param(); 
    if ($file_name) { 
     $response = array(
      $this->get_singular_param_name() => $this->get_file_object($file_name) 
     ); 
    } else { 
     $response = array(
      $this->options['param_name'] => $this->get_file_objects() 
     ); 
    } 
    return $this->generate_response($response, $print_response); 
} 

public function post($print_response = true) { 
    if ($this->get_query_param('_method') === 'DELETE') { 
     return $this->delete($print_response); 
    } 
    $upload = $this->get_upload_data($this->options['param_name']); 
    // Parse the Content-Disposition header, if available: 
    $content_disposition_header = $this->get_server_var('HTTP_CONTENT_DISPOSITION'); 
    $file_name = $content_disposition_header ? 
     rawurldecode(preg_replace(
      '/(^[^"]+")|("$)/', 
      '', 
      $content_disposition_header 
     )) : null; 
    // Parse the Content-Range header, which has the following form: 
    // Content-Range: bytes 0-524287/2000000 
    $content_range_header = $this->get_server_var('HTTP_CONTENT_RANGE'); 
    $content_range = $content_range_header ? 
     preg_split('/[^0-9]+/', $content_range_header) : null; 
    $size = $content_range ? $content_range[3] : null; 
    $files = array(); 
    if ($upload) { 
     if (is_array($upload['tmp_name'])) { 
      // param_name is an array identifier like "files[]", 
      // $upload is a multi-dimensional array: 
      foreach ($upload['tmp_name'] as $index => $value) { 
       $files[] = $this->handle_file_upload(
        $upload['tmp_name'][$index], 
        $file_name ? $file_name : $upload['name'][$index], 
        $size ? $size : $upload['size'][$index], 
        $upload['type'][$index], 
        $upload['error'][$index], 
        $index, 
        $content_range 
       ); 
      } 
     } else { 
      // param_name is a single object identifier like "file", 
      // $upload is a one-dimensional array: 
      $files[] = $this->handle_file_upload(
       isset($upload['tmp_name']) ? $upload['tmp_name'] : null, 
       $file_name ? $file_name : (isset($upload['name']) ? 
         $upload['name'] : null), 
       $size ? $size : (isset($upload['size']) ? 
         $upload['size'] : $this->get_server_var('CONTENT_LENGTH')), 
       isset($upload['type']) ? 
         $upload['type'] : $this->get_server_var('CONTENT_TYPE'), 
       isset($upload['error']) ? $upload['error'] : null, 
       null, 
       $content_range 
      ); 
     } 
    } 
    $response = array($this->options['param_name'] => $files); 
    return $this->generate_response($response, $print_response); 
} 

答えて

1

が、アップローダからの応答を取得するために、あなたはあなたの変数にメソッドget_response()を渡す必要があり、その後

$uploader = new UploadHandler(); 
$response = $uploader->get_response(); // returned as array 
// if your param_name is 'file' 
$response['file'][0]->custom_property = 'my address' 

あなたは今までのようにjsonに独自の値を追加できます。

関連する問題