Skip to content

Commit

Permalink
on peut mettre des photos de profil
Browse files Browse the repository at this point in the history
  • Loading branch information
Archii77 committed May 5, 2018
1 parent fb3be82 commit 16ac3b5
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 4 deletions.
20 changes: 18 additions & 2 deletions post_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,29 @@

//pour objectposts
$id = $_SESSION['id'];

$descri = isset($_POST["description"])?$_POST["description"]:null;
$pos = isset($_POST["position"])?$_POST["position"]:null;
$pseu = isset($_POST["pseudo"])?$_POST["pseudo"]:null;

if((isset($_FILES["fileToUpload"]) && !empty($_FILES["fileToUpload"]['name'])) || !empty($description)){

$target_file = null;

//include a picture
include("uploadPP.php");

$req = mysqli_prepare($db, "UPDATE users SET Description = ? , Position = ?, Pseudo = ?, ProfilePicture = ? WHERE ID = ?");
mysqli_stmt_bind_param($req, "ssssi",$descri, $pos, $pseu, $target_file, $id);

}
else{
$req = mysqli_prepare($db, "UPDATE users SET Description = ? , Position = ?, Pseudo = ? WHERE ID = ?");
mysqli_stmt_bind_param($req, "sssi",$descri, $pos, $pseu, $id);
}

// Modification
$req = mysqli_prepare($db, "UPDATE users SET Description = ? , Position = ?, Pseudo = ? WHERE ID = ?");
mysqli_stmt_bind_param($req, "sssi",$descri, $pos, $pseu, $id);

mysqli_stmt_execute($req);

mysqli_stmt_close($req);
Expand Down
8 changes: 8 additions & 0 deletions profile.css
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ img {
padding: 54px;
}

.profile-header-img img {
margin: 0 auto;
border-radius:200px;
width: 400px;
height: 400px;
object-fit: cover;
}

.profile-header-img > img.img-circle {
width: 230px;
height: 230px;
Expand Down
8 changes: 8 additions & 0 deletions profile_view.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ img {
/* border: 2px solid #51D2B7;*/
}

.profile-header-img img {
margin: 0 auto;
border-radius:200px;
width: 400px;
height: 400px;
object-fit: cover;
}

.profile-header {
margin-top: 30px;
}
Expand Down
8 changes: 8 additions & 0 deletions update.css
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ img {
padding: 54px;
}

.profile-header-img img {
margin: 0 auto;
border-radius:200px;
width: 400px;
height: 400px;
object-fit: cover;
}

.profile-header-img > img.img-circle {
width: 300px;
height: 300px;
Expand Down
4 changes: 2 additions & 2 deletions update.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
<div class="profile-header-container">
<div class="profile-header-img">
<?php
echo "<img class='img-circle' src='".$profilePicture."' />";
echo "<img src='".$profilePicture."' />";
?>
<!-- badge -->
<div class="rank-label-container">
Expand All @@ -109,7 +109,7 @@
<div class="jumbotron">
<h1>Update my profile</h1>
<br>
<form action="post_update.php" class="form-horizontal" method="post">
<form action="post_update.php" class="form-horizontal" method="post" enctype="multipart/form-data">
<label for="fileToUpload" class="btn btn-lg btn-default mr-sm-2" style="cursor: pointer;">Add a Profile Picture</label>
<input type="file" name="fileToUpload" value="fileToUpload" id="fileToUpload" accept=".jpg, .jpeg, .png">
<div class="preview">
Expand Down
63 changes: 63 additions & 0 deletions uploadPP.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
if(isset($_FILES["fileToUpload"]) && !empty($_FILES["fileToUpload"]['name'])){
$target_dir = "uploads/user$id/";
echo "yooo";
if (!is_dir($target_dir)) {
mkdir($target_dir, 0777, true);
}

$basename = basename($_FILES["fileToUpload"]["name"]);
$imageFileType = strtolower(pathinfo($basename,PATHINFO_EXTENSION));

$target_file = $target_dir."profilePicture.".$imageFileType;
$uploadOk = 1;

// Check if image file is a actual image or fake image

if(isset($_POST["submit"])) {
if (!file_exists($_FILES['fileToUpload']['tmp_name'])) {
echo "File upload failed. ";
if (isset($_FILES['fileToUpload']['error'])) {
echo "Error code: ".$_FILES['fileToUpload']['error'];
}
exit;
}
$file_temp = $_FILES['fileToUpload']['tmp_name'];
echo $file_temp;
$check = getimagesize($file_temp);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "file exists";
$uploadOk = 0;
}

// Check file size
if ($_FILES["fileToUpload"]["size"] > 5000000) {
echo "file is too big";
$uploadOk = 0;
}

// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "file not good";
$uploadOk = 0;
}

// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
// if everything is ok, try to upload file
} else {
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);
}
}

?>
Binary file added uploads/user6/profilePicture.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 16ac3b5

Please sign in to comment.