I'm starting with php and I'm already acquiring the basic knowledge, but I just faced a wall when trying to make a form with a field to upload a document and other input to put a number, and that when uploading the document, be renown with the number that I have assigned in the input. I know I need code to put, but I do not know how to do it.
I have this piece of code at this time
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input name="uploadedfile" type="file"/>
<input type="number" placeholder="Nº de Albarán">
<input type="submit" value="SUBIR Y COMPLETAR AVISO"/>
</form>
And here the function code
<?php
function dbConnect (){
$conn = null;
$host = 'Localhost';
$db = 'db_name';
$user = 'db_user';
$pwd = 'db_pass';
try {
$conn = new PDO('mysql:host='.$host.';dbname='.$db, $user, $pwd);
}
catch (PDOException $e) {
echo '<p>Error al conectar a la base de datos</p>';
exit;
}
return $conn;
}
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "El archivo ". basename( $_FILES['uploadedfile']['name']). " ha sido subido";
}
else{
echo "Ha ocurrido un error";
}
?>