php - how to encrypt an image name by a small string using laravel 6

Solution:

Instead of encrypting the file to get a random string, you could generate a hash.

 $imageName = hash('sha1', $image);

Function : https://www.php.net/manual/fr/function.hash.php

List of algo (so, you can choose the string length) : https://www.php.net/manual/fr/function.hash-algos.php

You can add a random number if you want the file name to be unique each time

 $imageName = hash('sha1', $image . random_int (100, 1000000));

Answer

Solution:

May you try something like this:

substr(base64_encode(sha1(mt_rand())), 0, 10)

In this example, we have a random string with 10 characters. You can replace the function mt_rand() by the original file name.

Source