How to generate random names for images that will be uploaded?

Asked

Viewed 70 times

0

I’m having trouble creating random names for my images. It was using the md5(mt_rand(1,10000) function but was unsuccessful using it in conjunction with has::file.

    public function anexar () {
        if(Input::hasFile('file')){
          $file = Input::file('file');
          $file->move('uploads', $file->getClientOriginalName());
          return 'Anexado com sucesso';
          }
        } 
    }

1 answer

1


You can use the uniqueid() function of PHP. It generates a unique id taking time into account, in microseconds. You can pass a prefix to the function it concatenates with the generated id.

For more information: http://us.php.net/manual/en/function.uniqid.php

  • Márcio Lordelo, I’m beginner n programming I could not understand very well the uniqueid ! It’s like you send an example based on my problem above ?

  • Hi @Márcio, I managed to solve the problem here using uniqueid ! Thanks for the tip brother.

  • opa, had not seen before you asking for an example, sorry, I stayed a few days without accessing. Glad you could =)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.