PHPackages                             cesurapp/media-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. cesurapp/media-bundle

ActiveSymfony-bundle[Image &amp; Media](/categories/media)

cesurapp/media-bundle
=====================

Symfony Media Bundle

1.2.12(2mo ago)0342MITPHPPHP &gt;=8.4CI passing

Since Dec 3Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/cesurapp/media-bundle)[ Packagist](https://packagist.org/packages/cesurapp/media-bundle)[ Docs](https://github.com/cesurapp/media-bundle)[ RSS](/packages/cesurapp-media-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (15)Versions (34)Used By (0)

Media Bundle
============

[](#media-bundle)

[![App Tester](https://github.com/cesurapp/media-bundle/actions/workflows/testing.yaml/badge.svg)](https://github.com/cesurapp/media-bundle/actions/workflows/testing.yaml)[![Software License](https://camo.githubusercontent.com/e99b24ac55a940bfbc522043865b6e8934548d8524587e0d1540d163ca9e85b3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f6c6f676f3d556e6c6963656e7365)](LICENSE.md)

Media management bundle for Symfony with automatic storage integration and reference counting.

**Features:**

- Automatic file tracking with reference counting
- Auto-cleanup when media is deleted or unused
- Image compression, resizing, and format conversion
- Multiple upload methods (HTTP, Base64, URL)
- Support for multiple media columns per entity
- Built on top of `cesurapp/storage-bundle`

Installation
------------

[](#installation)

**Requirements:**

- PHP 8.4+
- Symfony 8.0+

```
composer require cesurapp/media-bundle
```

Quick Start
-----------

[](#quick-start)

### 1. Add Media Column to Entity

[](#1-add-media-column-to-entity)

```
use Cesurapp\MediaBundle\Entity\{MediaInterface,Traits\MediaTrait};

class User implements MediaInterface
{
    use MediaTrait;

    // For single column, getMediaColumns() is optional
    // For multiple columns, override:
    public function getMediaColumns(): array
    {
        return ['media', 'avatar'];
    }
}
```

**Note:** Copy and rename `MediaTrait` for each additional media column (e.g., `LogoTrait`, `AvatarTrait`).

### 2. Upload Media

[](#2-upload-media)

```
use Cesurapp\MediaBundle\Manager\MediaManager;
use Symfony\Component\HttpFoundation\Request;

class UploadController
{
    public function upload(Request $request, MediaManager $manager): void
    {
        // Configure image processing
        $medias = $manager
            ->setImageCompress(true)        // Enable compression
            ->setImageConvertJPG(true)      // Convert PNG/JPEG to JPG
            ->setImageQuality(75)           // JPEG quality (0-100)
            ->setImageSize(1280, 720)       // Max dimensions (aspect ratio preserved)
            ->uploadFile($request);         // Upload HTTP files

        // Attach to entity
        $user->addMedias($medias);
    }
}
```

### 3. Upload Methods

[](#3-upload-methods)

```
// HTTP file upload
$medias = $manager->uploadFile($request, ['avatar', 'photos']);

// Base64 upload with MIME validation
$medias = $manager->uploadBase64(
    $request,
    ['image'],
    ['image' => ['image/png', 'image/jpeg']]
);

// Remote URL download
$medias = $manager->uploadLink(
    $request,
    ['imageUrl'],
    ['imageUrl' => ['image/png']]
);

// Direct content creation
$media = $manager->createMedia('image/png', 'png', $content, strlen($content));
```

### 4. Access Media

[](#4-access-media)

```
// Get all media
$allMedia = $user->getMedia();

// Get first media
$firstMedia = $user->getMedia()[0] ?? null;

// Using helper method (available in LogoTrait, etc.)
$logo = $user->getLogoFirst();

// Serve as HTTP response
return $media->getResponse($storage);

// Get file content
$content = $media->getContent($storage);

// Get file path
$path = $media->getPath(); // e.g., "2025/01/20/01hmz3k4.jpg"
```

### 5. Delete Media

[](#5-delete-media)

```
// Manual deletion
$em->remove($media);
$em->flush(); // File automatically deleted from storage

// Remove from entity (auto-cleanup via counter)
$user->removeMedia($media);
$em->flush(); // Media deleted if no other references

// Entity deletion (cascading cleanup)
$em->remove($user);
$em->flush(); // All associated media auto-deleted when counter reaches 0
```

Commands
--------

[](#commands)

```
# View media storage statistics
bin/console media:status
```

Documentation
-------------

[](#documentation)

For detailed usage, see [GUIDELINES.md](GUIDELINES.md)

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance84

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~25 days

Recently: every ~7 days

Total

33

Last Release

84d ago

PHP version history (3 changes)1.0.0PHP &gt;=8.2

1.1.0PHP &gt;=8.3

1.2.0PHP &gt;=8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/536cf2806f6fabc0e58a93484c57ee0ea9aba222f7ba9475a4d21a61cb1dbe96?d=identicon)[cesurapp](/maintainers/cesurapp)

---

Top Contributors

[![cesurapp](https://avatars.githubusercontent.com/u/8649070?v=4)](https://github.com/cesurapp "cesurapp (54 commits)")

---

Tags

bundlemedia-bundlepackagesymfonysymfonymedia bundle

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/cesurapp-media-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/cesurapp-media-bundle/health.svg)](https://phpackages.com/packages/cesurapp-media-bundle)
```

###  Alternatives

[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

7310.3k29](/packages/open-dxp-opendxp)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
