Update file compte.php
This commit is contained in:
parent
6c791b0b94
commit
f3cf2da609
@ -48,6 +48,73 @@ if(isset($_POST['user_display_name']) && isset($_POST['user_name']) && isset($_P
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_FILES['profile_picture']) && $_FILES['profile_picture']['error'] == 0) {
|
||||
// Chemins et noms de fichiers
|
||||
$tempPath = $_FILES['profile_picture']['tmp_name'];
|
||||
$path = 'src/pp/'. $_SESSION['userid'] .'.png';
|
||||
$finalPath = $wwwroot . $path;
|
||||
|
||||
// Redimensionnement de l'image
|
||||
$newWidth = 128;
|
||||
$newHeight = 128;
|
||||
$imageResized = imagecreatetruecolor($newWidth, $newHeight);
|
||||
$imageOriginal = imagecreatefromstring(file_get_contents($tempPath));
|
||||
imagecopyresampled($imageResized, $imageOriginal, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
|
||||
|
||||
// Enregistrement de l'image redimensionnée
|
||||
imagepng($imageResized, $finalPath);
|
||||
|
||||
// Nettoyage
|
||||
imagedestroy($imageOriginal);
|
||||
imagedestroy($imageResized);
|
||||
|
||||
$bdd = connect($dbhost, $dbname, $dbuser, $dbpass);
|
||||
$req = $bdd->prepare("UPDATE users SET profile_picture = :user_pp WHERE ID = :user_id");
|
||||
$req->bindParam(":user_pp", $path);
|
||||
$req->bindParam(":user_id", $_SESSION['userid']);
|
||||
if($req->execute()) {
|
||||
$status "PP mise à jour";
|
||||
} else {
|
||||
$status = "Erreur SQL";
|
||||
}
|
||||
} else {
|
||||
echo "Erreur upload";
|
||||
}
|
||||
|
||||
if (isset($_FILES['banner']) && $_FILES['banner']['error'] == 0) {
|
||||
// Chemins et noms de fichiers
|
||||
$tempPath = $_FILES['banner']['tmp_name'];
|
||||
$path = 'src/pp/'. $_SESSION['userid'] .'.png';
|
||||
$finalPath = $wwwroot . $path;
|
||||
|
||||
// Redimensionnement de l'image
|
||||
list($width, $height) = getimagesize($tempPath);
|
||||
$newWidth = 600;
|
||||
$newHeight = ($height / $width) * $newWidth;
|
||||
$imageResized = imagecreatetruecolor($newWidth, $newHeight);
|
||||
$imageOriginal = imagecreatefromstring(file_get_contents($tempPath));
|
||||
imagecopyresampled($imageResized, $imageOriginal, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
|
||||
|
||||
// Enregistrement de l'image redimensionnée
|
||||
imagepng($imageResized, $finalPath);
|
||||
|
||||
// Nettoyage
|
||||
imagedestroy($imageOriginal);
|
||||
imagedestroy($imageResized);
|
||||
|
||||
$bdd = connect($dbhost, $dbname, $dbuser, $dbpass);
|
||||
$req = $bdd->prepare("UPDATE users SET banner = :user_banner WHERE ID = :user_id");
|
||||
$req->bindParam(":user_banner", $path);
|
||||
$req->bindParam(":user_id", $_SESSION['userid']);
|
||||
if($req->execute()) {
|
||||
$status "Banière mise à jour";
|
||||
} else {
|
||||
$status = "Erreur SQL";
|
||||
}
|
||||
} else {
|
||||
echo "Erreur upload";
|
||||
}
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
@ -144,8 +211,9 @@ if(isset($_POST['user_display_name']) && isset($_POST['user_name']) && isset($_P
|
||||
<div class="username"><input type="text" name="user_name" value="<?=$user_name?>" required/></div>
|
||||
</div>
|
||||
<div><textarea class="bio-input" name="user_bio" placeholder="Bio..." maxlength="100"><?=$user_bio?></textarea></div>
|
||||
<div><label for="user_pp">URL PP : </label><input type="text" name="user_pp" placeholder="URL PP..." value="<?=$user_pp_url?>"></div>
|
||||
<div><label for="user_banner">Banière : </label><input type="text" name="user_banner" placeholder="URL Banière.." value="<?=$user_banner?>"></div>
|
||||
</form>
|
||||
<div><form><input type="file" name="profile_picture" placeholder="PP"><input type="submit">Mettre à jour</input></form></div>
|
||||
<div><form><input type="file" name="banner" placeholder="Banière"><input type="submit">Mettre à jour</input></form></div>
|
||||
<div><input type="submit" value="Mettre à jour"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user