I'm trying to create a form for the upload of .pdf file using PHP. The file seems to be uploaded correctly, however, when the directory where it supposed to be is empty.
Here is my HTML:
<form action="<?php echo 'editAzienda.php?azienda='.$azienda['idAz']?>" method="post" enctype="multipart/form-data">
<label for="download-info" class="font-weight-bold">Seleziona il materiale informativo che vuoi far scaricare all'utente</label><br>
<input type="file" name="filepdf"/><br/>
<input type="submit" class="btn btn-success text-white text-uppercase font-weight-bold mt-5" value="Carica file" name="upload_pdf"/>
</form>
And my PHP code:
<?php
$pdfPath = "uploaded_files/";
$maxSize = 1000000000000;
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['upload_pdf'])) {
if (is_uploaded_file($_FILES['filepdf']['tmp_name'])) {
if ($_FILES['filepdf']['type'] != "application/pdf") {
echo "<div class='col-12 col-md-4 offset-md-2'><div class='alert alert-danger mt-5'><p>Il file non è un PDF</p></div></div>";
} else if ($_FILES['filepdf']['size'] > $maxSize) {
echo "<div class='col-12 col-md-4 offset-md-2'><div class='alert alert-danger mt-5'><p class='error'>File troppo grande. Dimensione massima: ' . $maxSize . 'KB</p></div></div>";
} else {
$pdfName = 'file.pdf';
$result = move_uploaded_file($_FILES['filepdf']['tmp_name'], $pdfPath . $pdfName);
if ($result == 1) {
echo "<div class='col-12 col-md-4 offset-md-2'><div class='alert alert-success mt-5'><p class='error'>Materiale informativo caricato con successo!</p></div></div>";
} else {
echo "<div class='col-12 col-md-4 offset-md-2'><div class='alert alert-danger mt-5'><p class='error'>Si è verificato un errore</p></div></div>";
}
}
}
}
?>
When I try to upload a .pdf by the validations rules that I've set, the success message appears but there is no file in the folder.
Thanks for the help!
question from:
https://stackoverflow.com/questions/66060166/i-cant-upload-a-pdf-using-php 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…