コード例 #1
0
 public function testExists()
 {
     list($fsManager, $distributor) = $this->getMocks();
     $mockFile = m::mock('Xpressengine\\Storage\\File');
     $mockFile->disk = 'local';
     $mockFile->shouldReceive('getPathname')->andReturn('attached/filenamestring');
     $mockFilesystem = m::mock('Illuminate\\Contracts\\Filesystem\\Filesystem');
     $mockFilesystem->shouldReceive('exists')->once()->with('attached/filenamestring')->andReturn(true);
     $fsManager->shouldReceive('disk')->once()->with('local')->andReturn($mockFilesystem);
     $instance = new FileHandler($fsManager, $distributor);
     $this->assertTrue($instance->exists($mockFile));
 }
コード例 #2
0
 /**
  * file download from storage
  *
  * @param File        $file file instance
  * @param string|null $name name of be downloaded file
  * @return void
  * @throws FileDoesNotExistException
  */
 public function download(File $file, $name = null)
 {
     if ($this->files->exists($file) === false) {
         throw new FileDoesNotExistException();
     }
     $file->downloadCount++;
     $this->repo->update($file);
     $name = $name ?: $file->clientname;
     header('Content-Description: File Transfer');
     header('Content-Type: application/octet-stream');
     header(sprintf('Content-Disposition: attachment; filename=%s', $name));
     header("Content-Transfer-Encoding: binary");
     header('Expires: 0');
     header('Cache-Control: must-revalidate');
     header('Pragma: public');
     header('Content-Length: ' . $file->size);
     file_put_contents('php://output', $this->read($file));
 }