Differential D9561 Diff 22918 src/applications/files/controller/PhabricatorFileUploadDialogController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/controller/PhabricatorFileUploadDialogController.php
<?php | <?php | ||||
final class PhabricatorFileUploadDialogController | final class PhabricatorFileUploadDialogController | ||||
extends PhabricatorFileController { | extends PhabricatorFileController { | ||||
public function processRequest() { | public function processRequest() { | ||||
$request = $this->getRequest(); | $request = $this->getRequest(); | ||||
$user = $request->getUser(); | $viewer = $request->getUser(); | ||||
$dialog = id(new AphrontDialogView()) | $severity = AphrontErrorView::SEVERITY_NOTICE; | ||||
->setUser($user) | $errors = array( | ||||
pht( | |||||
'To upload files more easily, drag and drop them directly into '. | |||||
'the text of your comment.')); | |||||
$e_file = true; | |||||
if ($request->isFormPost()) { | |||||
$errors = array(); | |||||
$severity = AphrontErrorView::SEVERITY_ERROR; | |||||
if (!$request->getFileExists('file')) { | |||||
$e_file = pht('Required'); | |||||
$errors[] = pht('You must select a file to upload.'); | |||||
} else { | |||||
try { | |||||
$file = PhabricatorFile::newFromPHPUpload( | |||||
$_FILES['file'], | |||||
array( | |||||
'authorPHID' => $viewer->getPHID(), | |||||
'isExplicitUpload' => true, | |||||
)); | |||||
} catch (Exception $ex) { | |||||
$e_file = pht('Error'); | |||||
$errors[] = $ex->getMessage(); | |||||
} | |||||
} | |||||
if (!$errors) { | |||||
return id(new AphrontAjaxResponse())->setContent( | |||||
array( | |||||
'id' => $file->getID(), | |||||
'phid' => $file->getPHID(), | |||||
'uri' => $file->getBestURI(), | |||||
)); | |||||
} | |||||
} | |||||
$form = id(new AphrontFormView()) | |||||
->setUser($viewer) | |||||
->appendChild( | |||||
id(new AphrontFormFileControl()) | |||||
->setName('file') | |||||
->setError($e_file)); | |||||
$dialog = $this->newDialog() | |||||
->setFormEncoding('multipart/form-data') | |||||
->setTitle(pht('Upload File')) | ->setTitle(pht('Upload File')) | ||||
->appendChild(pht( | ->setWidth(AphrontDialogView::WIDTH_FORM) | ||||
'To add files, drag and drop them into the comment text area.')) | ->setErrors($errors) | ||||
->addCancelButton('/', pht('Close')); | ->setErrorSeverity($severity) | ||||
->appendChild($form->buildLayoutView()) | |||||
->addCancelButton('/', pht('Close')) | |||||
->addSubmitButton(pht('Upload File')); | |||||
return id(new AphrontDialogResponse())->setDialog($dialog); | return id(new AphrontDialogResponse())->setDialog($dialog); | ||||
} | } | ||||
} | } |