PHP-SharePoint-Lists-API icon indicating copy to clipboard operation
PHP-SharePoint-Lists-API copied to clipboard

Download List Item Attachment from SP Online

Open geme4472 opened this issue 9 years ago • 1 comments

Hello,

I've been using the additional features associated with the Copy webservice, as added by drjoju. When attempting to download items from a document library, getItem() works swimmingly to produce a file stream that can then be written locally. However, when presented with an SP list item's attachment (actually, the URL thereof, from getAttachments()), it spits out an empty object. I've Googled this over and over, to no avail, except for finding out how easily this is done in .NET. Has anyone had luck downloading attachments from an SP list?

geme4472 avatar Feb 03 '16 14:02 geme4472

I can't say this is the right way to do it, but it's what worked for me. You will need to get a login cookie for your SharePoint account (I used the Chrome plugin cookie.txt, and found that I need to replace the cookie once a week due to it expiring)

$ch = curl_init();
$url = "URL RETURNED BY getAttachments()";
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt( $ch, CURLOPT_COOKIEFILE,"PATH TO YOUR COOKIE FILE");
$imageData = curl_exec($ch);
file_put_contents("PATH WHERE YOU WANT TO SAVE THE IMAGE", $imageData);

mgroat avatar May 31 '16 16:05 mgroat