---
title: "Get Attachments"
description: "Retrieve document attachments from RavenDB using the session API with code examples in C#, Java, Python, PHP, and Node.js."
url: "https://docs.ravendb.net/7.2/document-extensions/attachments/get-attachments"
version: "7.2"
language: "php"
---

# Get Attachments

> Client language: PHP. Also available for [C#](https://docs.ravendb.net/7.2/document-extensions/attachments/get-attachments.md), [Java](https://docs.ravendb.net/7.2/document-extensions/attachments/get-attachments.java.md), [Python](https://docs.ravendb.net/7.2/document-extensions/attachments/get-attachments.python.md), [Node.js](https://docs.ravendb.net/7.2/document-extensions/attachments/get-attachments.nodejs.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

Several methods allow you to download attachments from a database:

Use `session.advanced.attachments.get` to download an attachment or multiple attachments.  
Use `session.advanced.attachments.getNames` to get all the names of a document's attachments.  
Use `session.advanced.attachments.getRevision` to download an attachment of a document revision.  
Use `session.advanced.attachments.exists` to determine if an attachment exists on a document.

## Syntax

```php
function get(object|string $idOrEntity, ?string $name): CloseableAttachmentResult;
function getNames(?object $entity): AttachmentNameArray;
function exists(?string $documentId, ?string $name): bool;
function getRevision(?string $documentId, ?string $name, ?string $changeVector): CloseableAttachmentResult;
```

## Example I

```php
$session = $store->openSession();
try {
  $album = $session->load(Album::class, "albums/1");

  $file1 = $session->advanced()->attachments()->get($album, "001.jpg");
  $file2 = $session->advanced()->attachments()->get("albums/1", "002.jpg");

  $data = $file1->getData();

  $attachmentDetails = $file1->getDetails();
  $name = $attachmentDetails->getName();
  $contentType = $attachmentDetails->getContentType();
  $hash = $attachmentDetails->getHash();
  $size = $attachmentDetails->getSize();
  $documentId = $attachmentDetails->getDocumentId();
  $changeVector = $attachmentDetails->getChangeVector();

  $attachmentNames = $session->advanced()->attachments()->getNames($album);
  /** @var AttachmentName $attachmentName */
  foreach ($attachmentNames as $attachmentName)
  {
      $name = $attachmentName->getName();
      $contentType = $attachmentName->getContentType();
      $hash = $attachmentName->getHash();
      $size = $attachmentName->getSize();
  }

  $exists = $session->advanced()->attachments()->exists("albums/1", "003.jpg");
} finally {
  $session->close();
}
```
