Guest User

Untitled

a guest
Sep 26th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.66 KB | None | 0 0
  1. <?php
  2.     include 'init.php';
  3.     if (!logged_in()) {
  4.         header('location: header.php');
  5.         exit();
  6.     }
  7.     include 'template/header.php';
  8. ?>
  9. <h3>Upload image</h3>
  10. <?php
  11.     if (isset($_FILES['image'], $_POST['album_id'])) {
  12.         $image_name = $_FILES['image']['name'];
  13.         $image_size = $_FILES['image']['size'];
  14.         $image_temp = $_FILES['image']['tmp_name'];
  15.         $allowed_ext = array('jpeg', 'jpg', 'png', 'gif');
  16.         $tmp = explode('.', $image_name);
  17.         $image_ext = strtolower(end($tmp));
  18.         $album_id = $_POST['album_id'];
  19.         $errors = array();
  20.         if (empty($image_name) || empty($album_id)) {
  21.             $errors[] = 'Don\t modify the HTML code faggot.';
  22.         } else {
  23.             if (in_array($image_ext, $allowed_ext) === false) {
  24.                 $errors[] = 'File extension not allowed.';
  25.             }
  26.             if ($image_size > 2097152) {
  27.                 $errors[] = 'Maximum file size is 2mb.';
  28.             }
  29.             if (album_check($album_id) === false) {
  30.                 $errors[] = 'Don\'t modify the HTML code faggot.';
  31.             }
  32.             if (!empty($errors)) {
  33.                 echo 'There are errors';
  34.             } else {
  35.                 echo 'There are no errors';
  36.             }
  37.         }
  38.     }
  39.     $albums = get_albums();
  40.     if (empty($albums)) {
  41.         echo '<p>You don\'t have any albums. Create one by clicking <a href="create_album.php">here</a>!</p>';
  42.     } else {
  43. ?>
  44.     <form action="" method="post" enctype="multipart/form-data">
  45.         <p>Choose a file: <br /><input type="file" name="image" /></p>
  46.         <p>
  47.             Choose an album:<br />
  48.             <select id="choose_album">
  49.             <?php
  50.                 foreach($albums as $album) {
  51.                     echo '<option value="', $album['id'] ,'">', $album['name'] ,'</option>';
  52.                 }
  53.             ?>
  54.             </select>
  55.         </p>
  56.         <p><input type="submit" value="Upload" /></p>
  57.     </form>
  58. <?php
  59.     }
  60.     include 'template/footer.php';
  61. ?>
Add Comment
Please, Sign In to add comment