0

I have a .pdf file client side that I would like to send in binary form to my server, which will be handling it with PHP.

Client side, I am using a POST request that looks like this:

var newFile = require("sdk/io/file");
var params = {};
params.log = newFile.read(filepath, "b");
var makeRequest = newRequest({
  url: "SERVERURL",
  headers: {
        "Content-Type": "application/pdf"
  },
  content: params,
  onComplete: function(response) {
    console.error(response.text);
  }
}).post();

On server side, I'm using

file_get_contents('php://input')

and file_put_contents to write to a path on the server.

I have tried base64_decode and urldecode on the input, neither of which have correctly regenerated the PDF on the server. With urldecode, I get a blank PDF with the correct number of pages, but no text.

I'm new to PHP, could someone help me out?

Thank you.

MonkeyZeus
  • 20,375
  • 4
  • 36
  • 77
Anda
  • 101
  • 3
  • Is `newRequest()` a custom function or is it native to JS? I cannot find any documentation for it. – MonkeyZeus Jul 26 '16 at 20:52
  • It's part of Mozilla Firefox's Add-on sdk. I'm developing a firefox extension. – Anda Jul 27 '16 at 14:14
  • I see. I've added that tag to your question. Have you tried out the solution in my answer below? – MonkeyZeus Jul 27 '16 at 14:25
  • I did change server-side to $_POST['log']. However, I think the issue is with front-end encoding in javascript. I can get text files to send no problem, but PDFs aren't being encoded for some reason. – Anda Jul 27 '16 at 15:13

1 Answers1

0

I do not know what all of your PHP code looks like but I would replace file_get_contents('php://input') with $_POST['log'].

MonkeyZeus
  • 20,375
  • 4
  • 36
  • 77