PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.0
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.0
3.3.1 V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 All 138 releases
bit-form / includes / Core / Integration / ZohoMail / FilesApiHelper.php

FilesApiHelper.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.0, at includes/Core/Integration/ZohoMail/FilesApiHelper.php

49 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * ZohoMail Files Api
5 *
6 */
7
8 namespace BitCode\BitForm\Core\Integration\ZohoMail;
9
10 use BitCode\BitForm\Core\Util\HttpHelper;
11
12 /**
13 * Provide functionality for Upload files
14 */
15 final class FilesApiHelper {
16 private $_defaultHeader;
17 private $_payloadBoundary;
18 private $_basepath;
19
20 public function __construct($tokenDetails, $formID, $entryID) {
21 $this->_payloadBoundary = wp_generate_password(24);
22 $this->_defaultHeader['Authorization'] = "Zoho-oauthtoken {$tokenDetails->access_token}";
23 $this->_defaultHeader['Content-Type'] = 'application/octet-stream; boundary=' . $this->_payloadBoundary;
24 $this->_basepath = BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID . DIRECTORY_SEPARATOR . $entryID . DIRECTORY_SEPARATOR;
25 }
26
27 public function uploadFiles($files, $accountId, $dataCenter) {
28 $uploadFileEndpoint = "https://mail.zoho.{$dataCenter}/api/accounts/{$accountId}/messages/attachments";
29
30 $payload = '';
31
32 if (file_exists("{$this->_basepath}{$files}")) {
33 $uploadFileEndpoint .= '?fileName=' . basename("{$this->_basepath}{$files}");
34 $payload .= '--' . $this->_payloadBoundary;
35 $payload .= "\r\n";
36 $payload .= 'Content-Disposition: form-data; Content-Transfer-Encoding: binary; name="' . 'file' .
37 '"; fileName="' . basename("{$this->_basepath}{$files}") . '"' . "\r\n";
38 $payload .= "\r\n";
39 $payload .= file_get_contents("{$this->_basepath}{$files}");
40 $payload .= "\r\n";
41 $payload .= '--' . $this->_payloadBoundary . '--';
42
43 $uploadResponse = HttpHelper::post($uploadFileEndpoint, $payload, $this->_defaultHeader);
44
45 return $uploadResponse;
46 }
47 }
48 }
49