php - How to upload PDF, DOC, DOCX file to mysql -
i created form uploads information database. @ point people can upload pdf, doc or docx files. how do code have?
my upload.php
<?php $servername = "localhost"; $username = "root"; $password = "usbw"; $dbname = "persons"; // create connection database $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("connection failed: " . $conn->connect_error); } // address append - prepare sql statement , bind params $stmt = $conn->prepare("insert address (address_street, address_housenumber, address_zipcode, address_city, address_state) values (?, ?, ?, ?, ?)"); $stmt->bind_param("sssss", $straat, $huisnummer, $postcode, $stad, $provincie); $straat = htmlspecialchars($_post[straat]); $huisnummer = htmlspecialchars($_post[huisnummer]); $postcode = htmlspecialchars($_post[postcode]); $stad = htmlspecialchars($_post[stad]); $provincie = htmlspecialchars($_post[provincie]); // execute statement $result = $stmt->execute(); if ($result === false) { die("error: " . $stmt->error); } // capture last inserted address_id $last_id = $conn->insert_id; // person append - prepare sql statement , bind params $stmt = $conn->prepare("insert person (person_firstname, person_lastname, person_email, person_phonenumber, person_cv, person_address) values (?, ?, ?, ?, ?, ?)"); $stmt->bind_param("sssssi", $firstname, $lastname, $email, $telephone, $cv, $last_id); $firstname = htmlspecialchars($_post[firstname]); $lastname = htmlspecialchars($_post[lastname]); $email = htmlspecialchars($_post[email]); $telephone = htmlspecialchars($_post[telephone]); $cv = htmlspecialchars($_post[cv]); // execute statement $result = $stmt->execute(); if ($result === true) { $url="http://localhost:8080/website/bedankt.php"; header ("location: $url"); } else { echo "error: " . $stmt->error; } $stmt->close(); $conn->close(); ?>
the field person_cv used store file attachment pdf, doc , docx only. in database used varchar(45) type because want upload file directory on server. if have suggestions recommend use one.
my form
<form method="post" action="functie.php"> <div class="col-sm-3"> <input name="firstname" id="name" type="text" class="form-control" placeholder="voornaam" required> </div> <div class="col-sm-3"> <input name="lastname" id="name" type="text" class="form-control" placeholder="achternaam" required> </div> <div class="col-sm-3"> <input name="straat" id="name" type="text" class="form-control" placeholder="straat" required> </div> <div class="col-sm-3"> <input name="huisnummer" id="name" type="text" class="form-control" placeholder="huisnummer" required> </div> <div class="col-sm-3"> <input name="postcode" id="name" type="text" class="form-control" placeholder="postcode" required> </div> <div class="col-sm-3"> <input name="stad" id="name" type="text" class="form-control" placeholder="stad" required> </div> <div class="col-sm-3"> <select name="provincie" id="name" type="text" class="form-control" placeholder="provincie" required> <option value="drenthe">drenthe</option> <option value="flevoland">flevoland</option> <option value="friesland">friesland</option> <option value="gelderland">gelderland</option> <option value="groningen">groningen</option> <option value="limburg">limburg</option> <option value="noord-brabant">noord-brabant</option> <option value="noord-holland">noord-holland</option> <option value="overijssel">overijssel</option> <option value="utrecht">utrecht</option> <option value="zeeland">zeeland</option> <option value="zuid-holland">zuid-holland</option> </select> </div> <div class="col-sm-3"> <input name="telephone" id="telephone" class="form-control" type="tel" placeholder="telefoonnummer"> </div> <div class="col-sm-3"> <input name="email" id="email" class="form-control" type="email" placeholder="email" required> </div> <div class="col-sm-3"> <input name="cv" id="cv" class="form-control" type="file" placeholder="cv"> </div> <div class="col-sm-3"> <input type="submit" class="btn btn-default btn-form" name="submit" value="solliciteer"/> </div> <input type="hidden" value="nieuwe sollicitatie slimme-meters-maken.nl" name="subject" id="subject"> </form>
Comments
Post a Comment