1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
| <?php
session_start(); // AU TOUT DEBUT du fichier
// ----------------------
// Connexion BDD
include('include_db.php');
// ----------------------
if (empty($_SESSION['Prenom'])) {
header('Location: index.php');
}
//Récupérer l'id dans l'url
$id = $_GET['id'];
//Extraire les données lié à l'id
$sql = "SELECT * FROM BDD WHERE Id=:Id";
$query = $db->prepare($sql);
$query->execute(array(':Id' => $id));
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
$lastname = $row['Nom'];
$name = $row['Prenom'];
}
$statusMsg = '';
// File upload path
if (!empty($_FILES['uploaded_file'])) {
$targetDir = "cv/";
$fileName = basename($_FILES["uploaded_file"]["name"]);
$targetFilePath = $targetDir . $fileName;
$fileType = pathinfo($targetFilePath, PATHINFO_EXTENSION);
if (isset($_POST["submit"]) && !empty($_FILES["uploaded_file"]["name"])) {
// Allow certain file formats
$allowTypes = array('pdf','docx', 'png');
if (in_array($fileType, $allowTypes)) {
// Upload file to server
if (move_uploaded_file($_FILES["uploaded_file"]["tmp_name"], $targetFilePath)) {
// Insert image file name into database
$insert = $db->query("INSERT into CV (id, file_name, uploaded_on) VALUES ('".$fileName."', NOW())");
if ($insert) {
$statusMsg = "The file ".$fileName. " has been uploaded successfully.";
} else {
$statusMsg = "File upload failed, please try again.";
}
} else {
$statusMsg = "Sorry, there was an error uploading your file.";
}
} else {
$statusMsg = 'Sorry, only JPG, JPEG, PNG, GIF, & PDF files are allowed to upload.';
}
} else {
$statusMsg = 'Please select a file to upload.';
}
echo $statusMsg;
}
/*if (!empty($_FILES['uploaded_file'])) {
$file = rand(1000, 100000)."-".$_FILES['uploaded_file']['name'];
$file_loc = $_FILES['uploaded_file']['tmp_name'];
$file_size = $_FILES['uploaded_file']['size'];
$file_type = $_FILES['uploaded_file']['type'];
$path = "cv/";
$path = $path . basename($_FILES['uploaded_file']['name']);
if (move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $path)) {
echo "Le CV ". basename($_FILES['uploaded_file']['name']).
" a bien été mis en ligne";
$upload_query = $db->query('INSERT INTO CV VALUES('$file','$file_type','$file_size')');
$upload_query->execute($upload_query);
header('Location: list.php');
} else {
header('Location: error_upload.php');
}
}*/
?>
<!DOCTYPE html>
<html>
<head>
<title>PA - Ajout par fichier CSV</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="css/add_csv.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="icon" href="https://www.proactiveacademy.fr/wp-content/uploads/2018/01/cropped-favicon-32x32.png" sizes="32x32" />
<link rel="stylesheet" href="//use.fontawesome.com/releases/v5.0.7/css/all.css">
</head>
<body class="d-flex flex-column justify-content-center">
<div id="page-content">
<nav class="navbar navbar-expand-md bg-dark navbar-dark">
<a class="navbar-brand"><img src="http://www.proactiveacademy.fr/wp-content/uploads/2018/01/p-proactive-1.png" class="img-fluid" alt="Responsive image"></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="collapsibleNavbar">
<ul class="navbar-nav mx-auto">
<li class="nav-item">
<a class="nav-link" href="list.php"><i class="fas fa-address-book"></i></a>
</li>
<li class="nav-item">
<a class="nav-link" href="add_csv.php"><i class="fas fa-users"></i></a>
</li>
<li class="nav-item">
<a class="nav-link" href="logout.php"><i class="fas fa-sign-out-alt"></i></a>
</li>
</ul>
</div>
<span class="navbar-text right-align" style="text-align: right;">Bienvenue, <?php echo $_SESSION['Prenom']?></span>
</nav>
<main class="flex-fill justify-content-center align-items-center">
<div class="container-fluid register align-self-center h-100">
<div class="jumbotron jumbotron-fluid align-self-center h-100 justify-content-center align-items-center text-center" style="width:100%;border-top-style:solid;border-top-color:grey;margin-top:2%;padding: 8%;border-bottom-style:solid;border-bottom-color:grey;">
<div class="form">
<form enctype="multipart/form-data" action="upload.php" method="POST">
<h1 class="display 4">Ajouter un CV pour <?php echo "$name "; echo "$lastname";?></h1><br/><br/>
<div class="custom-file" id="customFile" lang="fr">
<input type="file" name="uploaded_file" id="file" class="custom-file-input"/>
<label class="custom-file-label" for="exampleInputFile">
Choisir un fichier
</label>
</div><br/><br/>
<script>$('.custom-file-input').on('change', function() {
let fileName = $(this).val().split('\\').pop();
$(this).next('.custom-file-label').addClass("selected").html(fileName);
});</script><br/>
<input type="submit" class="btnRegister btn btn-dark btn-sm" value="Ajouter à la base de donnée" name="submit"/>
</div>
</div>
</form>
</div>
</main>
</body>
<div class="footer">
<div class="footer-copyright text-center py-3"><hr class="my-4" style="margin: auto;width: 40%;"></br><p class="text-muted">© <?php echo date("Y"); ?> Codé par Ethan</small></p></div>
</div>
</div>
</html> |
Partager