• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

Using spatie/media-library, how to rename a collection of uploaded files?

phplaravellaravel-medialibrary


PHP Snippet 1:

$request->file('photo')->extension()

PHP Snippet 2:

        $newFileName = Str::random(20) .'.'.$request->file('photo')->extension();

PHP Snippet 3:

            $item->addMedia($request->photo)->usingFileName($newFileName)->toMediaCollection('photo');

Related Snippets

Laravel display validation error

PhpSpreadSheet: How to save Workbook sheets in individual CSV files

Clients authentication and user authentication with laravel

NGINX: connect() to unix:/var/run/php7.2-fpm.sock failed (2: No such file or directory)

Convert every two values of an associative array into key-value pairs

How to add a custom field to all Woocommerce attribute terms using add_action

Component install error: JInstaller: :Install: File does not exist

Dynamic dropdown Ajax PHP request

Login if user is active using Laravel Breeze

Can't remotely connect to MySQL error (13) with PHP script, connecting through CLI works

Laravel websockets AWS EC2 - Connection failed

Laravel UUID generation

How to get page number on dompdf PDF when using "view"

phpunit - testing is painfully slow

woocommerce get_order_report_data to show order_item_id

About Contact Privacy policy Terms and conditions