Я хочу загрузить файл PDF в папку wp media и обновить поле ACF. - PullRequest
0 голосов
/ 04 апреля 2019

Я установил HTML 2 PDF-код и добавил его с помощью html2pdfrocket API, и когда я запускаю этот API, загружается PDF, и это нормально, я хочу, чтобы PDF загружался и выгружался также в медиатеке Wordpress.

  // Set parameters

  $postdata = http_build_query(
       array(
          'apikey' => $apikey,
          'value' => $value,
          'MarginBottom' => '10',
      'MarginLeft' => '10',
      'MarginRight' => '10',
          'MarginTop' => '10'
    )
  );

  $opts = array('http' =>
     array(
         'method'  => 'POST',
         'header'  => 'Content-type: application/x-www-form-urlencoded',
         'content' => $postdata
     )
  );

  $context  = stream_context_create($opts);

  // Convert the HTML string to a PDF using those parameters
  $result = file_get_contents('http://api.html2pdfrocket.com/pdf', false, 
  $context);


  header('Content-Description: File Transfer');
  header('Content-Type: application/pdf');
  header('Expires: 0');
  header('Cache-Control: must-revalidate');
  header('Pragma: public');
  header('Content-Length: ' . strlen($result));

  header('Content-Disposition: attachment; filename=' . 'My CV.pdf' );

  $results = file_get_contents("http://api.html2pdfrocket.com/pdf?apikey=" . urlencode($apikey) . "&value=" . urlencode($value));

  update_field('pdf_file', 'sdsd', 'user_'.$current_user->ID);

  echo $result;   //echo result auto download PDF but i want upload also.
...