PHPackages                             daycode/stup-images - 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. [File &amp; Storage](/categories/file-storage)
4. /
5. daycode/stup-images

ActiveLibrary[File &amp; Storage](/categories/file-storage)

daycode/stup-images
===================

Stup Images or Store Or Update Images is a Package For Storing / Updating the Images, More Clear Codes and Upgrade Readability

v1.3.0(6mo ago)1363MITPHP

Since Jul 24Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/dayCod/laravel-stup-images)[ Packagist](https://packagist.org/packages/daycode/stup-images)[ RSS](/packages/daycode-stup-images/feed)WikiDiscussions master Synced today

READMEChangelog (6)Dependencies (1)Versions (8)Used By (0)

Laravel Stup Image
==================

[](#laravel-stup-image)

**Stup Image** is a powerful Laravel package for storing and updating images with clean, readable code. Integrated with the Intervention Image library, it provides an elegant solution for handling file uploads with advanced features like automatic resizing, configurable filename hashing, and flexible storage options.

[![Downloads](https://camo.githubusercontent.com/e49ff3aecc3dcd944b86d7bf9da274d76c78e155dbc9988eff3b62086e7d75f1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646179636f64652f737475702d696d61676573)](https://packagist.org/packages/daycode/stup-images)[![License](https://camo.githubusercontent.com/9e1b086133a838eafaabc2ee5257c06f511b67e8637f5d819a1cda81c65e59fa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f646179636f64652f737475702d696d61676573)](https://packagist.org/packages/daycode/stup-images)

---

✨ Features
----------

[](#-features)

- 🚀 Simple and intuitive API for file uploads
- 🖼️ Automatic image resizing on upload
- 🔒 Configurable filename hashing for security
- 📁 Flexible storage disk configuration (local, S3, etc.)
- 🔄 Sync upload (replace old file automatically)
- 📦 Multiple file uploads support
- 🗑️ Easy file deletion
- ⚙️ Customizable configuration
- ✅ File extension validation

---

📦 Installation
--------------

[](#-installation)

### 1. Install via Composer

[](#1-install-via-composer)

```
composer require daycode/stup-images
```

### 2. Publish Configuration (Optional)

[](#2-publish-configuration-optional)

```
php artisan vendor:publish --tag=stup-image
```

This will create a `config/stup-image.php` file where you can customize the package behavior.

### 3. Configure Storage Disk

[](#3-configure-storage-disk)

Make sure your `config/filesystems.php` has the desired disk configured. By default, the package uses the `FILESYSTEM_DISK` from your `.env` file.

```
FILESYSTEM_DISK=public
```

### 4. Link Storage (if using public disk)

[](#4-link-storage-if-using-public-disk)

```
php artisan storage:link
```

### 5. Clear Cache

[](#5-clear-cache)

```
php artisan optimize:clear
```

---

⚙️ Configuration
----------------

[](#️-configuration)

After publishing the config file, you can customize these options in `config/stup-image.php`:

```
return [
    // Hash filenames using MD5 + timestamp for security
    'hash_filename' => true,

    // Allowed file extensions. Use ['*'] for all, or specify: ['jpg', 'png', 'gif']
    'allowed_extensions' => ['*'],
];
```

---

🚀 Usage
-------

[](#-usage)

### Basic Setup

[](#basic-setup)

Add the `Stupable` trait to your controller or any class:

```
use Daycode\StupImage\Stupable;

class UserController extends Controller
{
    use Stupable;

    // Your methods here...
}
```

---

### 📤 Upload File

[](#-upload-file)

Upload a single file to storage:

```
public function store(Request $request)
{
    $filename = $this->uploadFile(
        file: $request->file('avatar'),
        path: 'images/avatars'
    );

    User::create([
        'name' => $request->name,
        'avatar' => $filename,
    ]);

    return redirect()->back()->with('success', 'User created successfully!');
}
```

---

### 🖼️ Upload with Auto Resize

[](#️-upload-with-auto-resize)

Automatically resize images during upload:

```
public function store(Request $request)
{
    // Resize to 800x600 pixels
    $filename = $this->uploadFile(
        file: $request->file('thumbnail'),
        path: 'images/thumbnails',
        resize: [800, 600]
    );

    Post::create([
        'title' => $request->title,
        'thumbnail' => $filename,
    ]);
}
```

---

### 🔄 Sync Upload (Update &amp; Replace)

[](#-sync-upload-update--replace)

Upload a new file and automatically delete the old one:

```
public function update(Request $request, User $user)
{
    $filename = $user->avatar;

    if ($request->hasFile('avatar')) {
        $filename = $this->syncUploadFile(
            file: $request->file('avatar'),
            oldFileName: $user->avatar,
            path: 'images/avatars'
        );
    }

    $user->update([
        'name' => $request->name,
        'avatar' => $filename,
    ]);

    return redirect()->back()->with('success', 'User updated successfully!');
}
```

---

### 📦 Upload Multiple Files

[](#-upload-multiple-files)

Upload multiple files at once:

```
public function store(Request $request)
{
    $filenames = $this->uploadMultipleFiles(
        files: $request->file('gallery'),
        path: 'images/gallery'
    );

    foreach ($filenames as $filename) {
        Gallery::create([
            'image' => $filename,
        ]);
    }

    return redirect()->back()->with('success', 'Gallery uploaded successfully!');
}
```

---

### 🗑️ Delete File

[](#️-delete-file)

Delete a file from storage:

```
public function destroy(User $user)
{
    $this->deleteFile(
        fileName: $user->avatar,
        path: 'images/avatars'
    );

    $user->delete();

    return redirect()->back()->with('success', 'User deleted successfully!');
}
```

---

📖 API Reference
---------------

[](#-api-reference)

### `uploadFile(UploadedFile $file, string $path, ?array $resize = []): string`

[](#uploadfileuploadedfile-file-string-path-array-resize---string)

Upload a single file to storage.

**Parameters:**

- `$file` - The uploaded file instance
- `$path` - Storage path (relative to your configured disk)
- `$resize` - Optional. Array with `[width, height]` for automatic resizing

**Returns:** Filename (string) or throws `UploadException`

---

### `syncUploadFile(UploadedFile $file, ?string $oldFileName, string $path): string`

[](#syncuploadfileuploadedfile-file-string-oldfilename-string-path-string)

Upload a new file and delete the old one.

**Parameters:**

- `$file` - The new uploaded file
- `$oldFileName` - The old filename to delete (nullable)
- `$path` - Storage path
- `$resize` - Optional. Array with `[width, height]` for automatic resizing

**Returns:** New filename (string)

---

### `uploadMultipleFiles(array $files, string $path): array`

[](#uploadmultiplefilesarray-files-string-path-array)

Upload multiple files at once.

**Parameters:**

- `$files` - Array of uploaded files
- `$path` - Storage path
- `$resize` - Optional. Array with `[width, height]` for automatic resizing

**Returns:** Array of filenames or throws `UploadException`

---

### `deleteFile(string $fileName, string $path): void`

[](#deletefilestring-filename-string-path-void)

Delete a file from storage.

**Parameters:**

- `$fileName` - The filename to delete
- `$path` - Storage path

---

🔧 Advanced Configuration
------------------------

[](#-advanced-configuration)

### Using Different Storage Disks

[](#using-different-storage-disks)

The package respects your `FILESYSTEM_DISK` environment variable. To use different disks:

**Local Storage:**

```
FILESYSTEM_DISK=public
```

**Amazon S3:**

```
FILESYSTEM_DISK=s3
AWS_ACCESS_KEY_ID=your-key
AWS_SECRET_ACCESS_KEY=your-secret
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=your-bucket
```

**DigitalOcean Spaces, Cloudinary, etc.:**Configure your disk in `config/filesystems.php` and set `FILESYSTEM_DISK` accordingly.

---

### Restrict File Extensions

[](#restrict-file-extensions)

Edit `config/stup-image.php`:

```
'allowed_extensions' => ['jpg', 'jpeg', 'png', 'gif', 'webp'],
```

---

### Disable Filename Hashing

[](#disable-filename-hashing)

If you want to keep original filenames:

```
'hash_filename' => false,
```

---

🛡️ Security
-----------

[](#️-security)

- Filenames are hashed by default using MD5 + timestamp to prevent conflicts and enhance security
- File extension validation prevents unauthorized file types
- Uses Laravel's Storage facade for secure file handling

---

📝 Examples
----------

[](#-examples)

### Complete CRUD Example

[](#complete-crud-example)

```
use Daycode\StupImage\Stupable;

class ProductController extends Controller
{
    use Stupable;

    public function store(Request $request)
    {
        $request->validate([
            'name' => 'required',
            'image' => 'required|image|max:2048',
        ]);

        $filename = $this->uploadFile(
            file: $request->file('image'),
            path: 'products',
            resize: [1200, 800]
        );

        Product::create([
            'name' => $request->name,
            'image' => $filename,
        ]);

        return redirect()->route('products.index');
    }

    public function update(Request $request, Product $product)
    {
        $request->validate([
            'name' => 'required',
            'image' => 'nullable|image|max:2048',
        ]);

        $filename = $product->image;

        if ($request->hasFile('image')) {
            $filename = $this->syncUploadFile(
                file: $request->file('image'),
                oldFileName: $product->image,
                path: 'products'
            );
        }

        $product->update([
            'name' => $request->name,
            'image' => $filename,
        ]);

        return redirect()->route('products.index');
    }

    public function destroy(Product $product)
    {
        $this->deleteFile($product->image, 'products');
        $product->delete();

        return redirect()->route('products.index');
    }
}
```

---

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

---

📄 License
---------

[](#-license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

---

👨‍💻 Credits
-----------

[](#‍-credits)

- **Author:** [Wirandra Alaya (dayCod)](https://github.com/dayCod)
- **Intervention Image:** [Intervention](https://github.com/Intervention/image)

---

💬 Support
---------

[](#-support)

If you find this package helpful, please consider giving it a ⭐ on [GitHub](https://github.com/dayCod/laravel-stup-images) and [Packagist](https://packagist.org/packages/daycode/stup-images)!

For issues or questions, please use the [GitHub Issues](https://github.com/dayCod/laravel-stup-images/issues) page.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance66

Regular maintenance activity

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 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 ~174 days

Recently: every ~217 days

Total

6

Last Release

204d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/78329755?v=4)[Wirandra Alaya](/maintainers/dayCod)[@dayCod](https://github.com/dayCod)

---

Top Contributors

[![dayCod](https://avatars.githubusercontent.com/u/78329755?v=4)](https://github.com/dayCod "dayCod (28 commits)")

---

Tags

laravellaravel-packagephp

### Embed Badge

![Health badge](/badges/daycode-stup-images/health.svg)

```
[![Health](https://phpackages.com/badges/daycode-stup-images/health.svg)](https://phpackages.com/packages/daycode-stup-images)
```

###  Alternatives

[unisharp/laravel-filemanager

A file upload/editor intended for use with Laravel 5 to 10 and CKEditor / TinyMCE

2.2k3.5M85](/packages/unisharp-laravel-filemanager)[unopim/unopim

UnoPim Laravel PIM

10.5k2.4k](/packages/unopim-unopim)[barryvdh/elfinder-flysystem-driver

A Flysystem Driver for elFinder

1865.1M40](/packages/barryvdh-elfinder-flysystem-driver)[october/rain

October Rain Library

1601.7M83](/packages/october-rain)[code16/sharp

Laravel Content Management Framework

79164.7k8](/packages/code16-sharp)[symfony/ux-cropperjs

Cropper.js integration for Symfony

19346.6k3](/packages/symfony-ux-cropperjs)

PHPackages © 2026

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