Change the file name when uploading

Asked

Viewed 75 times

-3

How do I change the file name when uploading?

I would just like to add in the shipping of the file name the date('dmY').

if(!empty($_FILES['uploaded_file'])) {
        $path = "./uploads/arquivos/";
        $path = $path . basename( $_FILES['arquivo']['name']);

        if(move_uploaded_file($_FILES['arquivo']['tmp_name'], $path)) {
            echo "Enviado";
        } else{
            echo "Erro";
        }
    }

1 answer

0

you’ll have to blow up(explode()) the file name and with the resulting array join the date, follow the example:

$nomeETipo = explode('.',$file['name']);
        $fileName = $nomeETipo[0].date('dmY') . "." . $nomeETipo[1];

where $filename[0] is the file name and $filename[1] is the file extension.

Browser other questions tagged

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