Onenote API PHP - trying to post multiple PHP files, submit.php return blank page

138 Views Asked by At

I’m having some issues with modifying the sample PHP code from the Outlook API PHP code to iterate through a series of PHP files to post. I have the Client ID, Secret, and callback URL in the file correctly.

I’ve modified the code as follows:

submit.php:

    function createPageWithFile($pdffile)
    {

        $ch = $this->initCurl();

        //ISO 8601 standard time stamp
        $date = date('c');

        //Read the file into memory
        //Note that reading entire large files into memory could create problems if
        //  PHP doesn't have enough memory to work with
        $fileContents = file_get_contents($pdffile);

        //Includes the Presentation part and embedded file data part
        //Each has its own Content-Disposition and Content-Type headers
        //The request must end with a blank line to be a valid Multipart request
        $postdata = <<<POSTDATA
--{$this->boundary}
Content-Disposition: form-data; name="Presentation"
Content-Type: text/html

<!DOCTYPE html>
<html>
  <head>
    <title>A page created with a file attachment (PHP Sample)</title>
    <meta name="created" value="$date"/>
  </head>
  <body>
  <h1>This is a page with a PDF file attachment</h1>
    <object
        data-attachment="$pdffile"
        data="name:embeddedFile"
        type="application/pdf" />
    <img data-render-src="name:embeddedFile" alt="$pdffile" width="1500" />
  </body>
</html>
--{$this->boundary}
Content-Disposition: form-data; name="embeddedFile"
Content-Type: application/pdf

$fileContents
--{$this->boundary}--

POSTDATA;

        curl_setopt($ch,CURLOPT_POSTFIELDS,$postdata);
        $response = curl_exec($ch);
        $this->finish($ch,$response,$pdffile);
    }

Later in the same file:

        case "file":
            $pdffiles = glob('*.{pdf,PDF}', GLOB_BRACE);
            foreach($pdfiles as $pdffile) {
                $OneNoteRequest->createPageWithFile($pdffile);
              }
            break;

Ideas?

0

There are 0 best solutions below