因此,我有以下代码来上传PDF,我想对其进行重命名,因为如果它具有与现有名称相同的名称,它将替换旧的PDF。
这是我的代码:
$allowedExts = array("pdf");
$temp = explode(".", $_FILES["pdf_file"]["name"]);
$newfilename = round(microtime(true)) . '.' . end($temp);
$extension = end($temp);
$upload_pdf=$_FILES["pdf_file"]["name"];
move_uploaded_file($_FILES["pdf_file"]["tmp_name"],"anexos/" . $_FILES["pdf_file"]["name"]);
$querypdf = "INSERT INTO anexos (pdf_file,id_colaborador) VALUES (?,?)";
$qpdf = $pdo->prepare($querypdf);
$qpdf->execute(array($upload_pdf,$id));
//die(print_r($_FILES));
答案 0 :(得分:1)
您只需在move_uploaded_file
的第二个参数中更改文件名即可更改文件名。
$newfilename = round(microtime(true)) . '.' . end($temp);
move_uploaded_file($_FILES["pdf_file"]["tmp_name"],"anexos/" . $newfilename);