Skip to content
This repository was archived by the owner on Dec 16, 2021. It is now read-only.

Commit e73034b

Browse files
committed
Merge pull request #119 from constantcontact/master
Master
2 parents 845ca81 + 34656a4 commit e73034b

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

examples/importFromFile.php

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<title>Constant Contact API v2 Upload Contact File Example</title>
5+
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet">
6+
<link href="styles.css" rel="stylesheet">
7+
</head>
8+
9+
<!--
10+
README: Import Contacts from file example
11+
This example flow illustrates how a Constant Contact account owner can upload a file to their contacts. In order for this example to function
12+
properly, you must have a valid Constant Contact API Key as well as an access token. Both of these can be obtained from
13+
http://constantcontact.mashery.com.
14+
-->
15+
16+
<?php
17+
// require the autoloaders
18+
require_once '../src/Ctct/autoload.php';
19+
require_once '../vendor/autoload.php';
20+
21+
use Ctct\ConstantContact;
22+
23+
// Enter your Constant Contact APIKEY and ACCESS_TOKEN
24+
define("APIKEY", "ENTER YOUR API KEY");
25+
define("ACCESS_TOKEN", "ENTER YOUR ACCESS TOKEN");
26+
27+
$cc = new ConstantContact(APIKEY);
28+
29+
if ($_FILES) {
30+
$fileName = $_POST['file_name'];
31+
$lists = $_POST['lists'];
32+
$fileLocation = $_FILES['file']['tmp_name'];
33+
34+
$fileUploadStatus = $cc->activityService->createAddContactsActivityFromFile(ACCESS_TOKEN, $fileName, $fileLocation, $lists);
35+
36+
}
37+
38+
$contactLists = array();
39+
$params = array();
40+
$listsResult = $cc->listService->getLists(ACCESS_TOKEN, $params);
41+
foreach ($listsResult as $list) {
42+
array_push($contactLists, $list);
43+
}
44+
?>
45+
46+
<body>
47+
<div class="well">
48+
<h3>Import a spreadsheet of Contacts (.xls, .xlsx, .csv, .txt)</h3>
49+
50+
<form class="form-horizontal" name="submitFile" id="submitFile" method="POST" action="importFromFile.php" enctype="multipart/form-data">
51+
<div class="control-group">
52+
<label class="control-label" for="file_name">File Name</label>
53+
54+
<div class="controls">
55+
<input type="text" id="file_name" name="file_name" placeholder="File Name">
56+
</div>
57+
</div>
58+
<div class="control-group">
59+
<label class="control-label" for="file">File</label>
60+
61+
<div class="controls">
62+
<input type="file" id="file" name="file" placeholder="Choose File">
63+
</div>
64+
</div>
65+
<div class="control-group">
66+
<label class="control-label" for="folder">Folder</label>
67+
68+
<div class="controls">
69+
<select multiple name="lists">
70+
<?php
71+
foreach ($contactLists as $list) {
72+
echo '<option value="' . $list->id . '">' . $list->name . '</option>';
73+
}
74+
?>
75+
</select>
76+
77+
</div>
78+
</div>
79+
<div class="control-group">
80+
<label class="control-label">
81+
<div class="controls">
82+
<input type="submit" value="Submit" class="btn btn-primary"/>
83+
</div>
84+
</div>
85+
</form>
86+
</div>
87+
88+
<?php
89+
// print the details of the contact upload status to screen
90+
if (isset($fileUploadStatus)) {
91+
echo '<span class="label label-success">File Uploaded!</span>';
92+
echo '<div class="container alert-success"><pre class="success-pre">';
93+
94+
print_r($fileUploadStatus);
95+
96+
echo '</pre></div>';
97+
}
98+
?>
99+
100+
</body>
101+
</html>

0 commit comments

Comments
 (0)