Renamify is a package for Laravel used to rename a file before uploaded to prevent replacing exists file which has the same name to this new uploaded file.

Overview

Renamify

Laravel package for renaming file before uploaded on server.

Latest Version Total Downloads License GitHub forks GitHub Repo stars

Renamify is a package for Laravel used to rename a file before uploaded to prevent replacing exists file which has the same name to this new uploaded file. eg: If in a given file destination has a file called photo.jpg, new file name will be photo_1.jpg.

Getting Started

Requirements

  • PHP >= 7.2.5
  • Composer is required
  • Laravel 7.x, 8.x and 9.x

Installation

This package can be installed through composer require. Before install this, make sure that your are working with PHP >= 7.1 in your system. Just run the following command in your cmd or terminal:

 composer require mbere250/laravel-renamify

After you have installed Renamify package, open your Laravel config file config/app.php and add the following line.

In the $providers array add the service providers for this package.

 Mbere250\Renamify\Renamify::class,

Package initialization

Import Renamify package on controller using below line:

use Mbere250\Renamify\Renamify;

Usage

- Create routes routes/web.php
Route::view('/upload_view','upload_view')->name('upload_view');

Route::post('/upload_handler',[UploadController::class,'upload_handler'])->name('upload_handler');
- Create view resources/views/upload_view.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Upload file</title>
    <link rel="stylesheet" href="/bootstrap-3.1.1/css/bootstrap.min.css">
</head>
<body>
    <div class="container">
        <div class="row mt-3">
            <div class="col-md-6 col-md-offset-3 mt-3">
                <h4 class="text-center">Upload file</h4>
                <hr>
                <form action="{{ route('upload_handler') }}" method="POST" enctype="multipart/form-data" id="uploadForm">
                      @csrf
                      <div class="form-group">
                        <label for="my-input">file</label>
                        <input id="my-input" class="form-control" type="file" name="file">
                        <span class="text-danger error-text imagefile_error"></span>
                      </div>
                      <div class="form-group">
                        <button type="submit" class="btn btn-primary">Upload</button>
                      </div>
                </form>
            </div>
        </div>
    </div>
    

    <script src="/jquery-3.0.0.min.js"></script>
    <script src="/bootstrap-3.1.1/js/bootstrap.min.js"></script>
</body>
</html>
- Controller app/Http/Controllers/UploadController.php

When you need your file to be uploaded in public path of your application

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Exception;
use Mbere250\Renamify\Renamify;

class UploadController extends Controller
{
    public function upload_handler(Request $request){
        
        if( $request->hasFile('file') ){

            $path = 'uploads/';
            if ( !File::exists( public_path($path) ) ) {
                 File::makeDirectory(public_path($path),0777,true);
             }
            $file = $request->file('file');
            $filename = $file->getClientOriginalName();
            
            //Generate new file name
            $new_filename = Renamify::file_path( public_path($path), $filename )->generate();

            $upload = $file->move($path, $new_filename );
            
            if($upload){
                SavedFile::insert([
                    'filename' => $new_filename,
                ]);
            }
    
        }else{
            throw new Exception(' No file selected. ');
        }
        
    }


}

When you need your file to be uploaded in public storage path of your application:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Exception;
use Mbere250\Renamify\Renamify;

class UploadController extends Controller
{
    public function upload_handler(Request $request){
        
        if( $request->hasFile('file') ){

            $path = 'uploads/';
            if ( !File::exists(storage_path('public/'.$path)) ) {
                  File::makeDirectory(storage_path('public/'.$path),0777,true);
            }
            $file = $request->file('file');
            $filename = $file->getClientOriginalName();

            //Generate new file name
            $new_filename = Renamify::file_path(  storage_path('app/public/').$path , $filename )->generate();

            $upload = $file->storeAs( 'public/'.$path,$new_filename);

            
            if($upload){
                SavedFile::insert([
                    'filename' => $new_filename,
                ]);
            }

        }else{
            throw new Exception(' No file selected. ');
        }
        
    }

}

When you are using this package, you will be able to get file name as shown in the image below: 'Renamify'

License

Renamify is released under the MIT License.

You might also like...
Login system designed by fragX to validate the user and prevent unauthorized access to confidential data.

Login_System v.0.1 Login system designed by fragX to validate the user and prevent unauthorized access to confidential data. 🧐 Features Sign In and S

Clean up and prevent empty meta from being saved for Job, Company, or Resume listings in database

=== Empty Meta Cleanup for WP Job Manager === Contributors: tripflex Tags: wp job manager, meta, cleanup, wpjobmanager Requires at least: 5.2 Tested u

A simple validator package to check if the given zipcode has a valid Dutch zipcode format
A simple validator package to check if the given zipcode has a valid Dutch zipcode format

Laravel Dutch Zipcode Validator A simple validator package to check if the given zipcode has a valid Dutch zipcode format Table of Contents Installati

A university system that creates a timetable programm for subjects,classes and teachers which is used to create a programm for each semester. All this served as a website.

Timetable-System-Generator A university system that creates a timetable programm for subjects,classes and teachers which is used to create a programm

University, College, and High School name generator using fakerphp/faker

FakerSchools University, College, and High School name generator using fakerphp/faker Installation Add the FakerSchools library to your composer.json

Simple Arabic Laravel Dashboard , has basic settings and a nice layout . to make it easy for you to create fast dashboard
Simple Arabic Laravel Dashboard , has basic settings and a nice layout . to make it easy for you to create fast dashboard

Simple Arabic Laravel Dashboard ✅ Auto Seo ✅ Optimized Notifications With Images ✅ Smart Alerts ✅ Auto Js Validations ✅ Front End Alert ✅ Nice Image V

GeoLocation-Package - This package helps you to know the current language of the user, the country from which he is browsing, the currency of his country, and also whether he is using it vpn
GeoLocation-Package - This package helps you to know the current language of the user, the country from which he is browsing, the currency of his country, and also whether he is using it vpn

GeoLocation in PHP (API) 😍 😍 😍 This package helps you to know a lot of information about the current user by his ip address 😍 😍 😍 This package h

A Laravel package helps you add a complete real-time messaging system to your new / existing application with only one command.
A Laravel package helps you add a complete real-time messaging system to your new / existing application with only one command.

A Laravel package helps you add a complete real-time messaging system to your new / existing application with only one command.

Save Model is a Laravel package that allows you to save data in the database in a new way.

Save Model is a Laravel package that allows you to save data in the database in a new way. No need to worry about $guarded and $fillable properties in the model anymore. Just relax an use Save Model package.

Releases(v1.0.1)
Owner
MB'DUSENGE Callixte
MB'DUSENGE Callixte
Laravel package to normalize your data before saving into the database.

This package helps you normalize your data in order to save them into the database. The Goal is to having separate classes that handle the data normalization, and thus can be tested independently.

Nicolas Widart 11 Apr 21, 2021
A Laravel URL Shortener package that provides URL redirects with optionally protected URL password, URL expiration, open limits before expiration

A Laravel URL Shortener package that provides URL redirects with optionally protected URL password, URL expiration, open limits before expiration, ability to set feature activation dates, and click tracking out of the box for your Laravel applications.

YorCreative 53 Jan 4, 2023
Prevent users from reusing recently used passwords

Laravel Password History Validation Prevent users from reusing recently used passwords. Installation You can install the package via composer: compose

Paul Edward 67 Oct 10, 2022
This package adds support for verifying new email addresses: when a user updates its email address, it won't replace the old one until the new one is verified.

Laravel Verify New Email Laravel supports verifying email addresses out of the box. This package adds support for verifying new email addresses. When

Protone Media 300 Dec 30, 2022
Testbench Component is the de-facto package that has been designed to help you write tests for your Laravel package

Laravel Testing Helper for Packages Development Testbench Component is the de-facto package that has been designed to help you write tests for your La

Orchestra Platform 1.9k Dec 29, 2022
Run multiple websites using the same Laravel installation while keeping tenant specific data separated for fully independent multi-domain setups, previously github.com/hyn/multi-tenant

The unobtrusive Laravel package that makes your app multi tenant. Serving multiple websites, each with one or more hostnames from the same codebase. B

Tenancy 2.4k Jan 3, 2023
Run multiple websites using the same Laravel installation while keeping tenant specific data separated for fully independent multi-domain setups.

Tenancy for Laravel Enabling awesome Software as a Service with the Laravel framework. This is the successor of hyn/multi-tenant. Feel free to show su

Tenancy 1.1k Dec 30, 2022
Run multiple websites using the same Laravel installation while keeping tenant specific data separated for fully independent multi-domain setups, previously

Run multiple websites using the same Laravel installation while keeping tenant specific data separated for fully independent multi-domain setups, previously

Tenancy 2.4k Jan 3, 2023
Laravel package to convert English numbers to Bangla number or Bangla text, Bangla month name and Bangla Money Format

Number to Bangla Number, Word or Month Name in Laravel | Get Wordpress Plugin Laravel package to convert English numbers to Bangla number or Bangla te

Md. Rakibul Islam 50 Dec 26, 2022
Laravel package to convert English numbers to Bangla number or Bangla text, Bangla month name and Bangla Money Format

Number to Bangla Number, Word or Month Name in Laravel | Get Wordpress Plugin Laravel package to convert English numbers to Bangla number or Bangla te

Md. Rakibul Islam 50 Dec 26, 2022