-
Notifications
You must be signed in to change notification settings - Fork 10
/
upload.php
executable file
·52 lines (42 loc) · 1.34 KB
/
upload.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
<?php session_start();
include('lib/Box_Rest_Client.php');
$api_key = '';
$box_net = new Box_Rest_Client($api_key);
if(!array_key_exists('auth',$_SESSION) || empty($_SESSION['auth'])) {
$_SESSION['auth'] = $box_net->authenticate();
}
else {
$box_net->auth_token = $_SESSION['auth'];
}
if(array_key_exists('action',$_POST)) {
if($_POST['action'] == 'create_folder') {
$folder = new Box_Client_Folder();
$folder->attr('name', 'Test Folder.'.time());
$folder->attr('parent_id', 0);
$folder->attr('share', false);
echo $box_net->create($folder);
}
else if($_POST['action'] == 'upload_file') {
$file = new Box_Client_File($_FILES['file']['tmp_name'], $_FILES['file']['name']);
$file->attr('folder_id', 0);
echo $box_net->upload($file);
}
}
?>
<html>
<head>
<title>Upload Test</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="action" value="create_folder">
<label>Folder name: </label><input type="text" name="folder_name"> <button type="submit">Create</button>
</form>
<hr>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<input type="hidden" name="action" value="upload_file">
<label>Select File: </label><input type="file" name="file">
<button type="submit">Upload</button>
</form>
</body>
</html>