Oleg0341
Oleg0341

Reputation: 275

How to connect to the exchange 2013 EWS via php (just get photo)

How to connect to the exchange 2013 EWS just get photo ? What Library do I need (API) and how to embed it ? (I 'm beginner in php)

Here's a code I have now:

https://exchange.domen.local/ews/exchange.asmx/s/[email protected]&size=HR240x240

He ask me login/password. That's good. But I need a way to write the Login/password to the script. Thanks.

Upvotes: 1

Views: 770

Answers (2)

Greg Esposito
Greg Esposito

Reputation: 62

Here is how I handled this in PHP using curl. It is simple with no dependencies outside of curl.

Tested against an Exchange 2013 server. Saves to a file directly.

$server = ''; // owa.whatever.com, etc.
$user = ''; // username without domain info
$password = '';
$email_to_get = ''; // Email to pull photo
$fullurl = "https://$server/ews/Exchange.asmx/s/GetUserPhoto?email=$email_to_get&size=HR648x648"; //sizes defined at https://msdn.microsoft.com/en-us/library/jj194329(v=exchg.80).aspx
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $fullurl);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM | CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$user:$password");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$returned = curl_exec($ch);

$fp = fopen("pic.jpg", 'w'); // Save picture locally to .jpg
fwrite($fp, $returned);
fclose($fp);

header('Content-type: image/jpeg');
echo $returned; // Display the image on the page if desired

Upvotes: 1

BastianW
BastianW

Reputation: 2658

Your "Code" you provide is incomplete. You only trigger the URL but do not specify that you wish to fetch the picture from the xml stream.

The best way is to check the Microsoft HowTo here, it provides examples you could adjust to your needs. If you are unable to do that you might wish to check the PHP EWS library from here.

Upvotes: 0

Related Questions