Always keep the same name as a PDF file on upload

Asked

Viewed 147 times

-3

How can I keep the same name of a file at the time of upload, for example if the person chooses a file with the name spreadsheet.pdf I can always save it with a fixed name, as a.pdf document, today I do this in my script:

$arquivo = $_FILES["arquivo_pdf"];
$arquivo_nome = $arquivo["name"];

// Move o arquivo para o diretório especificado
set_time_limit(0);
$diretorio = "../diretorio/";
$arquivo_temporario = $_FILES['arquivo_pdf']["tmp_name"];   
move_uploaded_file($arquivo_temporario, $diretorio.$arquivo_nome);

Being $file_name is what I always intend to leave with the same name.

1 answer

3


Very simple. Just you set $arquivo_nome as documento.pdf.

$arquivo = $_FILES["arquivo_pdf"];
$arquivo_nome = 'documento.pdf';

// Move o arquivo para o diretório especificado
set_time_limit(0);
$diretorio = "../diretorio/";
$arquivo_temporario = $_FILES['arquivo_pdf']["tmp_name"];   
move_uploaded_file($arquivo_temporario, $diretorio.$arquivo_nome);
  • Thanks for the help @gpupo, thanks anyway.

Browser other questions tagged

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