exists() 공개 메소드

check exists a file
public exists ( File $file ) : boolean
$file File file instance
리턴 boolean
 public function testExists()
 {
     list($filesystem) = $this->getMocks();
     $instance = new FilesystemHandler($filesystem);
     $mockFile = m::mock('Xpressengine\\Storage\\File');
     $mockFile->shouldReceive('getAttribute')->once()->with('disk')->andReturn('local');
     $mockFile->shouldReceive('getPathname')->andReturn('attached/filenamestring');
     $mockFilesystem = m::mock('Illuminate\\Contracts\\Filesystem\\Filesystem');
     $mockFilesystem->shouldReceive('exists')->once()->with('attached/filenamestring')->andReturn(true);
     $filesystem->shouldReceive('disk')->once()->with('local')->andReturn($mockFilesystem);
     $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->increment('downloadCount');
     $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', $file->getContent());
 }