本文整理汇总了PHP中PhabricatorFile::initializeNewFile方法的典型用法代码示例。如果您正苦于以下问题:PHP PhabricatorFile::initializeNewFile方法的具体用法?PHP PhabricatorFile::initializeNewFile怎么用?PHP PhabricatorFile::initializeNewFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhabricatorFile
的用法示例。
在下文中一共展示了PhabricatorFile::initializeNewFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleRequest
public function handleRequest(AphrontRequest $request)
{
$viewer = $request->getUser();
$file = PhabricatorFile::initializeNewFile();
$e_file = true;
$errors = array();
if ($request->isFormPost()) {
$view_policy = $request->getStr('viewPolicy');
if (!$request->getFileExists('file')) {
$e_file = pht('Required');
$errors[] = pht('You must select a file to upload.');
} else {
$file = PhabricatorFile::newFromPHPUpload(idx($_FILES, 'file'), array('name' => $request->getStr('name'), 'authorPHID' => $viewer->getPHID(), 'viewPolicy' => $view_policy, 'isExplicitUpload' => true));
}
if (!$errors) {
return id(new AphrontRedirectResponse())->setURI($file->getInfoURI());
}
$file->setViewPolicy($view_policy);
}
$support_id = celerity_generate_unique_node_id();
$instructions = id(new AphrontFormMarkupControl())->setControlID($support_id)->setControlStyle('display: none')->setValue(hsprintf('<br /><br /><strong>%s</strong> %s<br /><br />', pht('Drag and Drop:'), pht('You can also upload files by dragging and dropping them from your ' . 'desktop onto this page or the Phabricator home page.')));
$policies = id(new PhabricatorPolicyQuery())->setViewer($viewer)->setObject($file)->execute();
$form = id(new AphrontFormView())->setUser($viewer)->setEncType('multipart/form-data')->appendChild(id(new AphrontFormFileControl())->setLabel(pht('File'))->setName('file')->setError($e_file))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Name'))->setName('name')->setValue($request->getStr('name')))->appendChild(id(new AphrontFormPolicyControl())->setUser($viewer)->setCapability(PhabricatorPolicyCapability::CAN_VIEW)->setPolicyObject($file)->setPolicies($policies)->setName('viewPolicy'))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Upload'))->addCancelButton('/file/'))->appendChild($instructions);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(pht('Upload'), $request->getRequestURI());
$crumbs->setBorder(true);
$title = pht('Upload File');
$global_upload = id(new PhabricatorGlobalUploadTargetView())->setUser($viewer)->setShowIfSupportedID($support_id);
$form_box = id(new PHUIObjectBoxView())->setHeaderText(pht('File'))->setFormErrors($errors)->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->setForm($form);
$header = id(new PHUIHeaderView())->setHeader($title)->setHeaderIcon('fa-upload');
$view = id(new PHUITwoColumnView())->setHeader($header)->setFooter(array($form_box, $global_upload));
return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild($view);
}
示例2: render
public function render()
{
$viewer = $this->getViewer();
if (!$viewer->isLoggedIn()) {
return null;
}
$instructions_id = 'phabricator-global-drag-and-drop-upload-instructions';
require_celerity_resource('global-drag-and-drop-css');
$hint_text = $this->getHintText();
if (!strlen($hint_text)) {
$hint_text = "⇪ " . pht('Drop Files to Upload');
}
// Use the configured default view policy. Drag and drop uploads use
// a more restrictive view policy if we don't specify a policy explicitly,
// as the more restrictive policy is correct for most drop targets (like
// Pholio uploads and Remarkup text areas).
$view_policy = $this->getViewPolicy();
if ($view_policy === null) {
$view_policy = PhabricatorFile::initializeNewFile()->getViewPolicy();
}
$submit_uri = $this->getSubmitURI();
$done_uri = '/file/query/authored/';
Javelin::initBehavior('global-drag-and-drop', array('ifSupported' => $this->showIfSupportedID, 'instructions' => $instructions_id, 'uploadURI' => '/file/dropupload/', 'submitURI' => $submit_uri, 'browseURI' => $done_uri, 'viewPolicy' => $view_policy, 'chunkThreshold' => PhabricatorFileStorageEngine::getChunkThreshold()));
return phutil_tag('div', array('id' => $instructions_id, 'class' => 'phabricator-global-upload-instructions', 'style' => 'display: none;'), $hint_text);
}