Php coding problem image related


#1

I want to strip all special characters and none eng characters from the image name I want it to be pure alphabet and numbers without whitespaces and-, + =? and so on how can I make that happened

and I also use the implode and explode functions to insert images into my database table and I want to transfer this

$splitImg = implode(', ', strtolower($_FILES['imagesThumbnails']['name']));

[quote=“AwadGorg, post:1, topic:135086, full:true”]
I want to strip all special characters and none eng characters from the image name I want it to be pure alphabet and numbers without whitespaces and-, + =? and so on how can I make that happened

and I also use the implode and explode functions to insert images into my database table and I want to transfer this

$splitImg = implode(', ', strtolower($_FILES['imagesThumbnails']['name']));

note the code abovde get the name of the uploaded images multiable image

to the lowercase letter but when I use the strtolower function nothing happened the character still the same upper
to the lowercase letter but when I use the strtolower function nothing happened the character still the same upper


#2

Why not generate a random name for the image? :smile:

First, declare this function:

function random_str($length, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
{
    $pieces = [];
    $max = mb_strlen($keyspace, '8bit') - 1;
    for ($i = 0; $i < $length; ++$i) {
        $pieces []= $keyspace[rand(0, $max)];
    }
    return implode('', $pieces);
}

Then, to generate a random string, just invoke the function using

$random = random_str(10);

10 can be replaced with any other number, it represents the lenght of the random number


#3

i think cause it will be bad when it cames to google images search engine


#4

Then this will do

$splitImg = preg_replace("/[^A-Za-z0-9 ]/", '', strtolower($_FILES['imagesThumbnails']['name']));