Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Take A QuizChallenge yourself and boost your learning! Start the quiz now to earn credits.
Take A QuizUnlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
Take A QuizKindly log in to use this feature. We’ll take you to the login page automatically.
LoginGeneral Tech Bugs & Fixes 3 years ago
User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.
I know this may have been abandoned but I am still leaving this answer here just in case anyone is trying out this code.
Using the above code the contents of the file is not sent through with the request and when the file is created/updated the contents of the file will be replaced with the boundary parameter created by the Content-Type header.
The change I did to this code was append the contents of the file to the Content-Type after the $mimType variable like so :
Content-Type:$mimeType\r\n\r\n".file_get_contents($filepath)
The result of the POST headers are as such :
Content-Type:text/plain testddddddddddddddddddddddddddddddddddddddddddddd; boundary=------------------------04414062f2c8e909
This was also tested using a pdf file and was successful.
No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
Kindly log in to use this feature. We’ll take you to the login page automatically.
LoginReady to take your education and career to the next level? Register today and join our growing community of learners and professionals.
Your experience on this site will be improved by allowing cookies. Read Cookie Policy
Your experience on this site will be improved by allowing cookies. Read Cookie Policy
manpreet
Best Answer
3 years ago
I am using Php curl to upload file to sharepoint api. I am able to successfully upload a text file using sharepoint rest api. However, when non-text files are uploaded, the file actually is uploaded with the correct size etc but the contents look corrupted and not displaying.
In the below code, the $digest value is got correctly from sharepoint contextinfo url (not shown in this code)
Any thoughts?
"; function getCurlValue($filename, $contentType, $postname) { // PHP 5.5 introduced a CurlFile object that deprecates the old @filename syntax // See: https://wiki.php.net/rfc/curl-file-upload if (function_exists('curl_file_create')) { return curl_file_create($filename, $contentType, $postname); } // Use the old style if using an older version of PHP $value = "@{$this->filename};filename=" . $postname; if ($contentType) { $value .= ';type=' . $contentType; } return $value; }