@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 62 lines 1.6 kB view raw
1<?php 2 3final class PhabricatorFileUploadDialogController 4 extends PhabricatorFileController { 5 6 public function handleRequest(AphrontRequest $request) { 7 $viewer = $request->getViewer(); 8 9 $e_file = true; 10 $errors = array(); 11 if ($request->isDialogFormPost()) { 12 $file_phids = $request->getStrList('filePHIDs'); 13 if ($file_phids) { 14 $files = id(new PhabricatorFileQuery()) 15 ->setViewer($viewer) 16 ->withPHIDs($file_phids) 17 ->setRaisePolicyExceptions(true) 18 ->execute(); 19 } else { 20 $files = array(); 21 } 22 23 if ($files) { 24 $results = array(); 25 foreach ($files as $file) { 26 $results[] = $file->getDragAndDropDictionary(); 27 } 28 29 $content = array( 30 'files' => $results, 31 ); 32 33 return id(new AphrontAjaxResponse())->setContent($content); 34 } else { 35 $e_file = pht('Required'); 36 $errors[] = pht('You must choose a file to upload.'); 37 } 38 } 39 40 if ($request->getURIData('single')) { 41 $allow_multiple = false; 42 } else { 43 $allow_multiple = true; 44 } 45 46 $form = id(new AphrontFormView()) 47 ->appendChild( 48 id(new PHUIFormFileControl()) 49 ->setName('filePHIDs') 50 ->setLabel(pht('Upload File')) 51 ->setAllowMultiple($allow_multiple) 52 ->setError($e_file)); 53 54 return $this->newDialog() 55 ->setTitle(pht('File')) 56 ->setErrors($errors) 57 ->appendForm($form) 58 ->addSubmitButton(pht('Upload')) 59 ->addCancelButton('/'); 60 } 61 62}