Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/files/controller/PhabricatorFileUploadController.php
12242 views
1
<?php
2
3
final class PhabricatorFileUploadController extends PhabricatorFileController {
4
5
public function isGlobalDragAndDropUploadEnabled() {
6
return true;
7
}
8
9
public function handleRequest(AphrontRequest $request) {
10
$viewer = $request->getUser();
11
12
$file = PhabricatorFile::initializeNewFile();
13
14
$e_file = true;
15
$errors = array();
16
if ($request->isFormPost()) {
17
$view_policy = $request->getStr('viewPolicy');
18
19
if (!$request->getFileExists('file')) {
20
$e_file = pht('Required');
21
$errors[] = pht('You must select a file to upload.');
22
} else {
23
$file = PhabricatorFile::newFromPHPUpload(
24
idx($_FILES, 'file'),
25
array(
26
'name' => $request->getStr('name'),
27
'authorPHID' => $viewer->getPHID(),
28
'viewPolicy' => $view_policy,
29
'isExplicitUpload' => true,
30
));
31
}
32
33
if (!$errors) {
34
return id(new AphrontRedirectResponse())->setURI($file->getInfoURI());
35
}
36
37
$file->setViewPolicy($view_policy);
38
}
39
40
$support_id = celerity_generate_unique_node_id();
41
$instructions = id(new AphrontFormMarkupControl())
42
->setControlID($support_id)
43
->setControlStyle('display: none')
44
->setValue(hsprintf(
45
'<br /><br /><strong>%s</strong> %s<br /><br />',
46
pht('Drag and Drop:'),
47
pht(
48
'You can also upload files by dragging and dropping them from your '.
49
'desktop onto this page or the home page.')));
50
51
$policies = id(new PhabricatorPolicyQuery())
52
->setViewer($viewer)
53
->setObject($file)
54
->execute();
55
56
$form = id(new AphrontFormView())
57
->setUser($viewer)
58
->setEncType('multipart/form-data')
59
->appendChild(
60
id(new AphrontFormFileControl())
61
->setLabel(pht('File'))
62
->setName('file')
63
->setError($e_file))
64
->appendChild(
65
id(new AphrontFormTextControl())
66
->setLabel(pht('Name'))
67
->setName('name')
68
->setValue($request->getStr('name')))
69
->appendChild(
70
id(new AphrontFormPolicyControl())
71
->setUser($viewer)
72
->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
73
->setPolicyObject($file)
74
->setPolicies($policies)
75
->setName('viewPolicy'))
76
->appendChild(
77
id(new AphrontFormSubmitControl())
78
->setValue(pht('Upload'))
79
->addCancelButton('/file/'))
80
->appendChild($instructions);
81
82
$crumbs = $this->buildApplicationCrumbs();
83
$crumbs->addTextCrumb(pht('Upload'), $request->getRequestURI());
84
$crumbs->setBorder(true);
85
86
$title = pht('Upload File');
87
88
$global_upload = id(new PhabricatorGlobalUploadTargetView())
89
->setUser($viewer)
90
->setShowIfSupportedID($support_id);
91
92
$form_box = id(new PHUIObjectBoxView())
93
->setHeaderText($title)
94
->setFormErrors($errors)
95
->setBackground(PHUIObjectBoxView::WHITE_CONFIG)
96
->setForm($form);
97
98
$view = id(new PHUITwoColumnView())
99
->setFooter(array(
100
$form_box,
101
$global_upload,
102
));
103
104
return $this->newPage()
105
->setTitle($title)
106
->setCrumbs($crumbs)
107
->appendChild($view);
108
}
109
110
}
111
112