Advertisement
Darkness4869

UserInterface.php

Jun 18th, 2020
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.46 KB | None | 0 0
  1. <?php
  2. // Starting session
  3. session_start();
  4. // Adding the API to post the retrieved data to the database
  5. require "../StormySystems.php";
  6. ?>
  7. <!DOCTYPE html>
  8. <html lang="en">
  9.     <head>
  10.         <meta charset="UTF-8" />
  11.         <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  12.         <title>
  13.             Stormy Systems
  14.         </title>
  15.         <link rel="stylesheet" href="../Stylesheets/UserInterface.css" />
  16.         <link rel="shortcut icon" href="../Images/Logo.ico" type="image/x-icon" />
  17.     </head>
  18.     <body>
  19.         <!-- Header -->
  20.         <header>
  21.             <div class="Logo">
  22.                 <img src="../Images/Logo.png" alt="Logo" class="Logo">
  23.             </div>
  24.             <!-- Username -->
  25.             <h4>
  26.                 <?php echo $_SESSION['UsersUsername']; ?>
  27.             </h4>
  28.             <!-- It will redirect the user to the log out process. -->
  29.             <a href="./Logout.php">
  30.                 Logout
  31.             </a>
  32.         </header>
  33.         <h1>
  34.             Post
  35.         </h1>
  36.         <!-- Posting Form -->
  37.         <div class="PostingForm">
  38.             <!-- Guide -->
  39.             <h2>
  40.                 Posting form
  41.             </h2>
  42.             <p>
  43.                 Please fill in this form to be able to post on the Portfolio page!
  44.             </p>
  45.             <form method="post" enctype="multipart/form-data">
  46.                 <div class="ImagePoster">
  47.                     <input type="file" name="Image" accept="image/*" id="ImageButton" required>
  48.                     <div id="Image">
  49.                         Choose a file
  50.                     </div>
  51.                 </div>
  52.                 <input type="text" name="Name" id="Name" placeholder="Name" required>
  53.                 <input type="text" name="Description" id="Description" placeholder="Description" required>
  54.                 <input type="url" name="Link" id="Link" placeholder="Link" required>
  55.                 <input type="url" name="SourceCodeDirectory" id="SourceCodeDirectory" placeholder="Source Code Directory" required>
  56.                 <input type="submit" value="Post" id="Post" name="Post">
  57.             </form>
  58.             <?php
  59.             if (isset($_POST['Post'])) {
  60.                 $ImageDirectory = "../Images/";
  61.                 // Basename function will return the name of the file
  62.                 $ImageFile = $ImageDirectory . basename($_FILES["Image"]["tmp_name"]);
  63.                 // Conditions to post the project!
  64.                 if (move_uploaded_file($_FILES["Image"]["tmp_name"], $ImageFile)) {
  65.                     // Project class which will retrieve the form to handle all the storing process
  66.                     class Project {
  67.                         // Image Directory Accessor Method
  68.                         public function getImageDirectory() {
  69.                             return "../Images/" . basename($_FILES["Image"]["tmp_name"]);
  70.                         }
  71.                         // Name Accessor Method
  72.                         public function getName() {
  73.                             return $_POST["Name"];
  74.                         }
  75.                         // Description Accessor Method
  76.                         public function getDescription() {
  77.                             return $_POST["Description"];
  78.                         }
  79.                         // Link Accessor Method
  80.                         public function getLink() {
  81.                             return $_POST["Link"];
  82.                         }
  83.                         // Source Code Directory Accessor Method
  84.                         public function getSourceCodeDirectory() {
  85.                             return $_POST["SourceCodeDirectory"];
  86.                         }
  87.                     }
  88.                     // Instantiating Project class
  89.                     $Project = new Project();
  90.                     $ProjectImage = $Project->getImageDirectory();
  91.                     $ProjectName = $Project->getName();
  92.                     $ProjectDescription = $Project->getDescription();
  93.                     $ProjectLink = $Project->getLink();
  94.                     $ProjectSourceCode = $Project->getSourceCodeDirectory();
  95.                     // Instantiating Stormy Systems class
  96.                     $StormySystems = new StormySystems();
  97.                     // Insertion query for storing the project for later use
  98.                     $Query = "INSERT INTO project (ProjectImage, ProjectName, ProjectDescription, ProjectLink, ProjectSourceCode) VALUES (:ProjectImage, :ProjectName, :ProjectDescription, :ProjectLink, :ProjectSourceCode)";
  99.                     // Binding all the values from the form.
  100.                     $StormySystems->bind(":ProjectImage", $ProjectImage);
  101.                     $StormySystems->bind(":ProjectName", $ProjectName);
  102.                     $StormySystems->bind(":ProjectDescription", $ProjectDescription);
  103.                     $StormySystems->bind(":ProjectLink", $ProjectLink);
  104.                     $StormySystems->bind(":ProjectSourceCode", $ProjectSourceCode);
  105.                     // Executing the query
  106.                     $StormySystems->Execute();
  107.                     $Message = "<h1 class='Success'> The project has been successfully posted! </h1>";
  108.                 } else {
  109.                     $Message = "<h1 class='Failure'> The file cannot be uploaded to the server.  Therefore, the project cannot be posted! </h1>";
  110.                     echo $Message;
  111.                 }
  112.             }
  113.             ?>
  114.         </div>
  115.     </body>
  116. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement