Sri Kaliswari College(Autonomous), Sivakasi
Department of Information Technology
2023 – 2024 (Odd Semester)
Problem Solving Report
Class: III – B.Sc(IT)
Course Code and Course Name : 21UITC52 and Open Source Technology
Course Teacher: Mrs.I.Santhiya
Team Members:
S.No NAME OF THE STUDENT REGISTER NUMBER
1. B.DEEPA A11UIT001
2. M.KANMANI A11UIT003
3. M.KASTHURI A11UIT004
4. M.MADHU MITHA A11UIT005
5. N.MAHADEVI A11UIT006
6. G.MUNI PRIYA A11UIT007
Problem Description:
You build a exam apply portal ,You want to allow users to upload an image file, and
after the upload, you want to perform some basic processing, such as resizing the image and
saving it to the server.
Tools/Techniques necessary to solve the problem:
Open Source technology – PHP scripts
Suggested Model:
Using move_uploaded_file
Proposed Solution:
Index.php:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Online Exam Registration</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f2f2f2;
}
header {
background-color: #002366;
color: white;
padding: 20px;
text-align: center;
}
.container {
width: 80%;
margin: 0 auto;
padding: 20px;
}
form {
background-color: #fff;
padding: 20px;
border-radius: 5px;
}
input[type="text"],
input[type="email"],
input[type="submit"] {
width: 100%;
padding: 10px;
margin-bottom: 10px;
border-radius: 5px;
border: 1px solid #ccc;
}
input[type="submit"] {
background-color: #002366;
color: white;
cursor: pointer;
}
</style>
</head>
<body>
<header>
<h1>Online Exam Registration</h1>
</header>
<div class="container">
<form action="uploads.php" method="POST" enctype="multipart/form-data">
<label for="fullname">Full Name:</label>
<input type="text" id="fullname" name="fullname" required>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<label for="phone">Phone Number:</label>
<input type="text" id="phone" name="phone" required>
<br><br>
<label for="exam_type">Exam Type:</label>
<select id="exam_type" name="exam_type">
<option value="IELTS">IELTS</option>
<option value="TOEFL">TOEFL</option>
<option value="GRE">GRE</option>
<option value="SAT">SAT</option>
<option value="NET">NET</option>
</select>
<br><br>
<label>ID Proof : </label>
<input type="file" name="image">
<br><br>
<label>Address:</label>
<input type="text" id="fullname" name="fullname" required>
<br>
<input type="submit" value="Register">
</form>
</div>
</body>
</html>
Uploads.php:
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['submit'])) {
$target_dir = "uploads/"; // Directory where the image will be saved
$target_file = $target_dir . basename($_FILES["image"]["name"]); // Path to the uploaded
image
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
$check = getimagesize($_FILES["image"]["tmp_name"]);
if ($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["image"]["size"] > 500000) { // Adjust size limit as needed
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif") {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// If everything is OK, try to upload file
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
} else {
// Resize and save the image
move_uploaded_file($_FILES["image"]["tmp_name"], $target_file);
// Basic image resizing (adjust dimensions as needed)
$resized_image = imagecreatefromjpeg($target_file);
$resized = imagescale($resized_image, 200, 200); // Resize to 200x200 pixels
imagejpeg($resized, $target_file); // Save resized image
imagedestroy($resized); // Clean up resources
echo "The file " . basename($_FILES["image"]["name"]) . " has been uploaded and
resized.";
}
}
?>
Solution Output:
Comment of the Course Teacher: