getChunkPath() public method

Return chunk path
public getChunkPath ( integer $index ) : string
$index integer
return string
示例#1
0
文件: FileTest.php 项目: mrsad/Dru.io
 /**
  * @covers ::getChunkPath
  */
 public function testFile_construct_getChunkPath()
 {
     $request = new Request($this->requestArr);
     $file = new File($this->config, $request);
     $expPath = $this->vfs->url() . DIRECTORY_SEPARATOR . sha1($this->requestArr['flowIdentifier']) . '_1';
     $this->assertSame($expPath, $file->getChunkPath(1));
 }
示例#2
0
文件: Uploader.php 项目: entrt/Aisel
 /**
  * uploadFile
  *
  * @param  string $mediaDir
  * @param  Request $request
  * @throws HttpException
  *
  * @return string
  */
 public static function uploadFile($mediaDir, Request $request)
 {
     $uploadedFile = null;
     if ($request->files->get('file')) {
         /** @var \Symfony\Component\HttpFoundation\File\UploadedFile $fileFromFileBag */
         $fileFromFileBag = $request->files->get('file');
         $uploadedFile = array('name' => $fileFromFileBag->getClientOriginalName(), 'type' => $fileFromFileBag->getMimeType(), 'tmp_name' => $fileFromFileBag->getPathname(), 'error' => $fileFromFileBag->getError(), 'size' => $fileFromFileBag->getSize());
     }
     $config = new FlowConfig();
     $config->setTempDir($mediaDir);
     $flowRequest = new FlowRequest($request->request->all(), $uploadedFile);
     $flowFile = new FlowFile($config, $flowRequest);
     if ($request->getMethod() === 'GET') {
         if ($flowFile->checkChunk()) {
             header("HTTP/1.1 200 Ok");
         } else {
             header("HTTP/1.1 204 No Content");
             return false;
         }
     } else {
         if ($flowFile->validateChunk()) {
             rename($uploadedFile['tmp_name'], $flowFile->getChunkPath($flowRequest->getCurrentChunkNumber()));
         } else {
             throw new HttpException(400);
         }
     }
     $filename = $mediaDir . '/' . $uploadedFile['name'];
     if ($flowFile->validateFile() && $flowFile->save($filename)) {
         return $filename;
     } else {
         // This is not a final chunk, continue to upload
     }
     return false;
 }