You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 22, 2024. It is now read-only.
I modified the code to iterate through all the PDF files in the same directory to OneNote, but now submit.php is not working (it's giving me a blank page, no errors).
Ideas? The relevant code blocks are the CreatePageWithFile($submittedFile) and the finish() function.
function createPageWithFile($submittedFile)
{
$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
$nameofFile = basename($submittedFile);
$fullFileName = basename($submittedFile) . ".pdf";
$fileContents = file_get_contents($submittedFile);
//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>nameofFile</title>
<meta name="created" value="$date"/>
</head>
<body>
<object
data-attachment="$fullFileName"
data="name:$fullFileName"
type="application/pdf" />
<img data-render-src="name:$fullFileName"/>
</body>
</html>
--{$this->boundary}
Content-Disposition: form-data; name="$fullFileName"
Content-Type: application/pdf
$fileContents
--{$this->boundary}--
POSTDATA;
curl_setopt($ch,CURLOPT_POSTFIELDS,$postdata);
$response = curl_exec($ch);
$this->finish($ch,$response,$submittedFile);
}
[ . . . ]
function finish($ch,$response,$submittedFile)
{
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] == 201)
{
unlink($submittedFile);
echo '<h2>Page created!</h2>';
$response_without_header = substr($response,$info['header_size']);
$decoded = json_decode($response_without_header);
echo 'Open page in <a href="'.
$decoded->links->oneNoteClientUrl->href.
'">OneNote</a> or <a href="'.
$decoded->links->oneNoteWebUrl->href.
'">OneNote Online</a>';
}
elseif ($info['http_code'] == 401)
{
echo '<h2>Authorization failed. Try signing out and signing in again.</h2>';
}
else
{
echo '<h2>Something went wrong...</h2>';
}
echo '</b></h2>';
echo '<h3>Response</h3>';
echo '<pre>';
echo htmlspecialchars($response);
echo '</pre>';
}
}
[ . . . ]
case "file":
foreach (glob("*.[pP][dD][fF]") as $submittedFile {
$OneNoteRequest->createPageWithFile($submittedFile);
}
break;
I modified the code to iterate through all the PDF files in the same directory to OneNote, but now submit.php is not working (it's giving me a blank page, no errors).
Ideas? The relevant code blocks are the
CreatePageWithFile($submittedFile)and thefinish()function.