Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions gio_kutsia/week1/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<html>

<head>
<title></title>
<link rel="stylesheet" href="styles/main.css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
</head>

<body class="container">

<?php include "validation.php" ?>
<?php if(empty($_POST) || !empty($nameErr) || !empty($lastnameErr) ||!empty($errorFile)): ?>


<div class="main-div ">
<form action="" method="post" enctype="multipart/form-data">
<div class=" ">

<input class="form-control mb-5" name="name" type="text" placeholder="firstname"
value="<?= $name;?>"></input>
<span style="color:red"><?= $nameErr ?></span>
<input class="form-control mb-5" name="lastname" type="text" placeholder="lastname"
value="<?= $lastname;?>"></input>
<span style="color:red"><?= $lastnameErr ?></span>
<input class=" form-control mb-5" name="added_photo" type="file">
<span style="color:red"><?= $errorFile ?></span>
<input class="form-control mb-3" type="submit" name="submit_form" value="submit">
</div>
</form>
</div>
<?php else: ?>


<div class="card-div card mb-3 mt-5">
<img src="<?php print "uploads/" . $porfile_image; ?>" class="card-img-top" alt="Profile photo">
<div class="card-body ">
<h3 class="card-text">Info</h3>
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item"> <small class="text-muted">First Name:</small><?= $name ?></li>
<li class="list-group-item"><small class="text-muted">Last Name: </small><?= $lastname ?></li>
<li class="list-group-item"><small class="text-muted">Uploaded date: </small><?= print date('d/Y/M')?></li>
</ul>
</div>
<?php endif; ?>


</body>

</html>
10 changes: 10 additions & 0 deletions gio_kutsia/week1/styles/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.main-div {

width: 25%;
margin: 50px auto;
}

.card-div {
width: 35%;
margin: 50px auto;
}
50 changes: 50 additions & 0 deletions gio_kutsia/week1/validation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
$name = $lastname = "";
$nameErr = $lastnameErr =$errorFile= "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$nameErr = "Name is required";
} else {
$name = $_POST["name"];

if (!preg_match("/^[a-zA-Z-' ]*$/",$name)) {
$nameErr = "Only letters and white space allowed";
}
}
if(empty($_POST["lastname"])){
$lastnameErr = "Last Name is required";
} else {
$lastname = $_POST["lastname"];

if(!preg_match("/^[a-zA-Z-' ]*$/",$lastname)){
$lastnameErr = "Only letters and white space allowed";
}
}
}

if(isset($_FILES['added_photo'])){
$target_dir = getcwd() . "/uploads/";
$porfile_image = basename($_FILES["added_photo"]["name"]);
$allowed_ext = array("jpg" => "image/jpg",
"jpeg" => "image/jpeg",
"gif" => "image/gif",
"png" => "image/png");
$profile_image_url = NULL;
$ext = pathinfo($porfile_image, PATHINFO_EXTENSION);
if (!array_key_exists($ext, $allowed_ext)) {
$errorFile="please use JPG PNG JPEG GIF PNG";
}
if(in_array($_FILES["added_photo"]["type"], $allowed_ext)) {
if(!file_exists($target_dir)) {
mkdir($target_dir);
}
if(move_uploaded_file($_FILES["added_photo"]["tmp_name"], $target_dir . $porfile_image) ){
$profile_image_url = $target_dir.$porfile_image;
}
}


}


?>
2 changes: 2 additions & 0 deletions gio_kutsia/week2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# dependencies
/node_modules
Loading