This repository has been archived by the owner on Aug 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 114
/
example.php
52 lines (46 loc) · 1.93 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Dropbox Uploader Demo</title>
</head>
<body>
<h1>Dropbox Uploader Demo</h1>
<?php
if ($_POST) {
require 'DropboxUploader.php';
try {
$uploader = null;
if ($_FILES['file']['error'] !== UPLOAD_ERR_OK)
throw new Exception('File was not successfully uploaded from your computer.');
if ($_FILES['file']['name'] === "")
throw new Exception('File name not supplied by the browser.');
// Upload
$uploader = new DropboxUploader($_POST['email'], $_POST['password']);
$uploader->upload($_FILES['file']['tmp_name'], $_POST['destination'], $_FILES['file']['name']);
echo '<span style="color: green">File successfully uploaded to your Dropbox!</span>';
} catch (Exception $e) {
// Handle Upload Exceptions
$label = ($uploader && $e->getCode() & $uploader::FLAG_DROPBOX_GENERIC) ? 'DropboxUploader' : 'Exception';
$error = sprintf("[%s] #%d %s", $label, $e->getCode(), $e->getMessage());
echo '<span style="color: red">Error: ' . htmlspecialchars($error) . '</span>';
}
}
?>
<form method="POST" enctype="multipart/form-data">
<dl>
<dt><label for="email">Dropbox e-mail</label></dt>
<dd><input type="text" id="email" name="email"></dd>
<dt><label for="password">Dropbox password</label></dt>
<dd><input type="password" id="password" name="password"></dd>
<dt><label for="destination">Destination directory (optional)</label></dt>
<dd><input type="text" id="destination" name="destination"> e.g. "dir/subdirectory", will be created if it
doesn't exist
</dd>
<dt><label for="file"></label>File</dt>
<dd><input type="file" id="file" name="file"></dd>
<dd><input type="submit" value="Upload the file to my Dropbox!"></dd>
</dl>
</form>
</body>
</html>