0
I have the following code and do not know how to change it to dynamically rename the image at the time of upload.
PHP
<?php
$uploaddir = './fotos/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "Arquivo válido e enviado com sucesso.\n";
} else {
echo "Possível ataque de upload de arquivo!\n";
}
echo 'Aqui está mais informações de debug:';
print_r($_FILES);
print "</pre>";
?>
You know what your code does line by line?
– Woss
@Andersoncarloswoss yes. I do. rss
– Gladison
@Andersoncarloswoss I have difficulty implementing md5 to generate random names for images.
– Gladison
So how do you think you change the file name?
– Woss
@Andersoncarloswoss I believe capturing the file name, renaming and sending to the line
move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)
. Is that?– Gladison
Exactly. If you look at documentation, the second parameter of
move_uploaded_file
is$destination
, referring to the final file name. The name you give it here will be written to disk.– Woss
Let’s go continue this discussion in chat.
– Gladison