当前位置: 首页>>代码示例>>PHP>>正文


PHP UploadBase::getStashFile方法代码示例

本文整理汇总了PHP中UploadBase::getStashFile方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadBase::getStashFile方法的具体用法?PHP UploadBase::getStashFile怎么用?PHP UploadBase::getStashFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UploadBase的用法示例。


在下文中一共展示了UploadBase::getStashFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getChunkResult

 /**
  * Get the result of a chunk upload.
  * @param array $warnings Array of Api upload warnings
  * @return array
  */
 private function getChunkResult($warnings)
 {
     $result = [];
     if ($warnings && count($warnings) > 0) {
         $result['warnings'] = $warnings;
     }
     $request = $this->getMain()->getRequest();
     $chunkPath = $request->getFileTempname('chunk');
     $chunkSize = $request->getUpload('chunk')->getSize();
     $totalSoFar = $this->mParams['offset'] + $chunkSize;
     $minChunkSize = $this->getConfig()->get('MinUploadChunkSize');
     // Sanity check sizing
     if ($totalSoFar > $this->mParams['filesize']) {
         $this->dieUsage('Offset plus current chunk is greater than claimed file size', 'invalid-chunk');
     }
     // Enforce minimum chunk size
     if ($totalSoFar != $this->mParams['filesize'] && $chunkSize < $minChunkSize) {
         $this->dieUsage("Minimum chunk size is {$minChunkSize} bytes for non-final chunks", 'chunk-too-small');
     }
     if ($this->mParams['offset'] == 0) {
         $filekey = $this->performStash('critical');
     } else {
         $filekey = $this->mParams['filekey'];
         // Don't allow further uploads to an already-completed session
         $progress = UploadBase::getSessionStatus($this->getUser(), $filekey);
         if (!$progress) {
             // Probably can't get here, but check anyway just in case
             $this->dieUsage('No chunked upload session with this key', 'stashfailed');
         } elseif ($progress['result'] !== 'Continue' || $progress['stage'] !== 'uploading') {
             $this->dieUsage('Chunked upload is already completed, check status for details', 'stashfailed');
         }
         $status = $this->mUpload->addChunk($chunkPath, $chunkSize, $this->mParams['offset']);
         if (!$status->isGood()) {
             $extradata = ['offset' => $this->mUpload->getOffset()];
             $this->dieStatusWithCode($status, 'stashfailed', $extradata);
         }
     }
     // Check we added the last chunk:
     if ($totalSoFar == $this->mParams['filesize']) {
         if ($this->mParams['async']) {
             UploadBase::setSessionStatus($this->getUser(), $filekey, ['result' => 'Poll', 'stage' => 'queued', 'status' => Status::newGood()]);
             JobQueueGroup::singleton()->push(new AssembleUploadChunksJob(Title::makeTitle(NS_FILE, $filekey), ['filename' => $this->mParams['filename'], 'filekey' => $filekey, 'session' => $this->getContext()->exportSession()]));
             $result['result'] = 'Poll';
             $result['stage'] = 'queued';
         } else {
             $status = $this->mUpload->concatenateChunks();
             if (!$status->isGood()) {
                 UploadBase::setSessionStatus($this->getUser(), $filekey, ['result' => 'Failure', 'stage' => 'assembling', 'status' => $status]);
                 $this->dieStatusWithCode($status, 'stashfailed');
             }
             // We can only get warnings like 'duplicate' after concatenating the chunks
             $warnings = $this->getApiWarnings();
             if ($warnings) {
                 $result['warnings'] = $warnings;
             }
             // The fully concatenated file has a new filekey. So remove
             // the old filekey and fetch the new one.
             UploadBase::setSessionStatus($this->getUser(), $filekey, false);
             $this->mUpload->stash->removeFile($filekey);
             $filekey = $this->mUpload->getStashFile()->getFileKey();
             $result['result'] = 'Success';
         }
     } else {
         UploadBase::setSessionStatus($this->getUser(), $filekey, ['result' => 'Continue', 'stage' => 'uploading', 'offset' => $totalSoFar, 'status' => Status::newGood()]);
         $result['result'] = 'Continue';
         $result['offset'] = $totalSoFar;
     }
     $result['filekey'] = $filekey;
     return $result;
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:75,代码来源:ApiUpload.php


注:本文中的UploadBase::getStashFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。