Advertisement
lowheartrate

posts.php // upload.php

Oct 18th, 2015
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.67 KB | None | 0 0
  1. <?php
  2. if (isset($_SESSION['level']) > 0) {
  3.     echo '
  4.     <form action="upload.php" method="POST" enctype="multipart/form-data">
  5.         <input style="color: #A30000; margin-bottom: 10px;" type="text" name="title" placeholder="Post Title" required/><br/>
  6.         <input style="color: #A30000; margin-bottom: 10px;" type="date" name="date" required/><br />
  7.         <span style="font-weight: bold; font-family: arial;">Image:</span><br/>
  8.         <input style="margin-bottom: 10px;" type="file" name="fileToUpload" id="fileToUpload"/><br />
  9.         <textarea style="margin-bottom: 10px; color: #A30000; width: 320px; height: 200px;" type="text" name="summary" placeholder="Summary" required></textarea><br />
  10.         <input value="Create Post" type="submit"/>
  11.     </form>
  12.     ';
  13. } else {
  14.     echo 'You are not an admin so can not view this part of the page.';
  15. }
  16.  
  17.  
  18.  
  19. /* upload.php */
  20. $target_dir = "uploads/";
  21. $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
  22. $uploadOk = 1;
  23. $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
  24.  
  25. // Check if image file is an actual or fake image
  26. if(isset($_POST["submit"])) {
  27.     $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
  28.     if($check !== false) {
  29.         $uploadOk = 1;
  30.     } else {
  31.         $uploadOk = 0;
  32.     }
  33. }
  34.  
  35. // Check if file already exists
  36. if (file_exists($target_file)) {
  37.     echo "Sorry, file already exists.";
  38.     $uploadOk = 0;
  39. }
  40.  
  41. // Allow certain file formats
  42. if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" ) {
  43.     echo "Sorry, only JPG, JPEG, & PNG files are allowed.";
  44.     $uploadOk = 0;
  45. }
  46.  
  47. // Check file width / height
  48.     // Need to figure out how to only allow images that are 1920 x 1080 as well as 1280 x 720
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement